
// CelsusView.cpp : implementation of the CCelsusView class
//

#include "stdafx.h"
#include "Celsus.h"

#include "CelsusDoc.h"
#include "CelsusView.h"
#include "MainFrm.h"

#include "SendMessage.h"
#include "DlgLogon.h"
#include "DlgEditUser.h"
#include "DlgEditStaff.h"
#include "DlgEditLibrary.h"
#include "DlgEditCollection.h"
#include "DlgEditPriority.h"
#include "DlgEditMethod.h"
#include "DlgEditNotes.h"
#include "DlgEditRequest.h"
#include "DlgEditStatus.h"
#include "DlgChangeLibrary.h"
#include "DlgFindRequest.h"
#include "DlgSearchRequest.h"
#include "DlgSendRequest.h"
#include "DlgSendFileHtml.h"
#include "DlgHoldRequest.h"
#include "DlgRequestNA.h"
#include "DlgSendLink.h"
#include "DlgFixRequest.h"
#include "DlgRequestFind.h"
#include "DlgComplete.h"
#include "DlgCheckOnline.h"
#include "DlgAddRequest.h"
#include "DlgCompleteManual.h"
#include "DlgHistoryList.h"
#include "DlgPreviewHTML.h"
#include "DlgLocateRequest.h"
#include "DlgConfirm.h"
#include "DlgEditText.h"
#include "DlgAddLDAPUser.h"
#include "DlgEditExternalILL.h"
#include "DlgEditLinks.h"
#include "DlgListSource.h"
#include "DlgPickUser.h"
#include "DlgEditSource.h"
#include "DlgEditILL.h"
#include "DlgPrintProcess.h"
#include "DlgEditHTML.h"

#include <Mmsystem.h>
#pragma comment(lib, "Winmm.lib")


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CCelsusView

IMPLEMENT_DYNCREATE(CCelsusView, CFormView)

BEGIN_MESSAGE_MAP(CCelsusView, CFormView)
	ON_WM_SIZE()
	ON_WM_CONTEXTMENU()
	ON_WM_TIMER()
	ON_NOTIFY(LVN_GETDISPINFO, IDC_LIST_REQUESTS, &CCelsusView::OnLvnGetdispinfoListRequests)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_REQUESTS, &CCelsusView::OnNMCustomdrawListRequests)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_REQUESTS, &CCelsusView::OnLvnItemchangedListRequests)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_CTRL, &CCelsusView::OnTcnSelchangeTabCtrl)
	ON_NOTIFY(NM_CLICK, IDC_LIST_REQUESTS, &CCelsusView::OnNMClickListRequests)
	ON_COMMAND(ID_EDIT_USERS_CURRENT, &CCelsusView::OnEditUsersCurrent)
	ON_COMMAND(ID_EDIT_USERS_PICK, &CCelsusView::OnEditUsersPick)
	ON_UPDATE_COMMAND_UI(ID_EDIT_USERS_CURRENT, &CCelsusView::OnUpdateEditUsersCurrent)
	ON_COMMAND(ID_EDIT_STAFF_PICK, &CCelsusView::OnEditStaffPick)
	ON_COMMAND(ID_EDIT_STAFF_CURRENT, &CCelsusView::OnEditStaffCurrent)
	ON_UPDATE_COMMAND_UI(ID_EDIT_STAFF_CURRENT, &CCelsusView::OnUpdateEditStaffCurrent)
	ON_COMMAND(ID_EDIT_STAFF_ADD, &CCelsusView::OnEditStaffAdd)
	ON_COMMAND(ID_REQUEST_EDIT, &CCelsusView::OnRequestEdit)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_EDIT, &CCelsusView::OnUpdateRequestEdit)
	ON_COMMAND(ID_FILE_CHANGELIBRARY, &CCelsusView::OnFileChangelibrary)
	ON_COMMAND(ID_EDIT_PREFERENCES, &CCelsusView::OnEditPreferences)
	ON_COMMAND(ID_REQUEST_SENDTOLIBRARY, &CCelsusView::OnRequestSendtolibrary)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_SENDTOLIBRARY, &CCelsusView::OnUpdateRequestSendtolibrary)
	ON_COMMAND(ID_REQUEST_CLAIM, &CCelsusView::OnRequestClaim)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_CLAIM, &CCelsusView::OnUpdateRequestClaim)
	ON_COMMAND(ID_REQUEST_OPEN, &CCelsusView::OnRequestOpen)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_OPEN, &CCelsusView::OnUpdateRequestOpen)
	ON_COMMAND(ID_REQUEST_SENDTOPROCESSING, &CCelsusView::OnRequestSendtoprocessing)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_SENDTOPROCESSING, &CCelsusView::OnUpdateRequestSendtoprocessing)
	ON_COMMAND(ID_REQUEST_REFRESH, &CCelsusView::OnRequestRefresh)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, &CCelsusView::OnUpdateEditCopy)
	ON_COMMAND(ID_EDIT_COPY, &CCelsusView::OnEditCopy)
	ON_COMMAND(ID_EDIT_FIND_REQUEST, &CCelsusView::OnEditFindRequest)
	ON_COMMAND(ID_REQUEST_PRINTSELECTED, &CCelsusView::OnRequestPrintselected)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_PRINTSELECTED, &CCelsusView::OnUpdateRequestPrintselected)
	ON_COMMAND(ID_REQUEST_RELEASE, &CCelsusView::OnRequestRelease)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_RELEASE, &CCelsusView::OnUpdateRequestRelease)
	ON_COMMAND(ID_REQUEST_PROCESS, &CCelsusView::OnRequestProcess)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_PROCESS, &CCelsusView::OnUpdateRequestProcess)
	ON_NOTIFY(HDN_ITEMCLICK, 0, &CCelsusView::OnHdnItemclickListRequests)
	ON_COMMAND(ID_REQUEST_MARKASHELD, &CCelsusView::OnRequestMarkasheld)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_MARKASHELD, &CCelsusView::OnUpdateRequestMarkasheld)
	ON_COMMAND(ID_REQUEST_SENDLINK, &CCelsusView::OnRequestSendlink)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_SENDLINK, &CCelsusView::OnUpdateRequestSendlink)
	ON_COMMAND(ID_REQUEST_SPLIT, &CCelsusView::OnRequestSplit)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_SPLIT, &CCelsusView::OnUpdateRequestSplit)
	ON_COMMAND(ID_REQUEST_COMBINE, &CCelsusView::OnRequestCombine)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_COMBINE, &CCelsusView::OnUpdateRequestCombine)
	ON_NOTIFY(LVN_ODFINDITEM, IDC_LIST_REQUESTS, &CCelsusView::OnLvnOdfinditemListRequests)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_REQUESTS, &CCelsusView::OnNMDblclkListRequests)
	ON_COMMAND(ID_FILE_PRINTSELECTED, &CCelsusView::OnFilePrintselected)
	ON_UPDATE_COMMAND_UI(ID_FILE_PRINTSELECTED, &CCelsusView::OnUpdateFilePrintselected)
	ON_COMMAND(ID_REQUEST_RESUBMIT, &CCelsusView::OnRequestResubmit)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_RESUBMIT, &CCelsusView::OnUpdateRequestResubmit)
	ON_COMMAND(ID_RECORD_EXPORTTOEXCEL, &CCelsusView::OnRecordExporttoexcel)
	ON_COMMAND(ID_REQUEST_NOTAVAILABLE, &CCelsusView::OnRequestNotavailable)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_NOTAVAILABLE, &CCelsusView::OnUpdateRequestNotavailable)
	ON_COMMAND(ID_REQUEST_RESENDEMAIL, &CCelsusView::OnRequestResendemail)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_RESENDEMAIL, &CCelsusView::OnUpdateRequestResendemail)
	ON_COMMAND(ID_EDIT_USERS_ADD, &CCelsusView::OnEditUsersAdd)
	ON_COMMAND(ID_REQUEST_CHECKONLINE, &CCelsusView::OnRequestCheckonline)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_CHECKONLINE, &CCelsusView::OnUpdateRequestCheckonline)
	ON_COMMAND(ID_EDIT_LIBRARY_PICK, &CCelsusView::OnEditLibraryPick)
	ON_COMMAND(ID_EDIT_LIBRARY_ADD, &CCelsusView::OnEditLibraryAdd)
	ON_COMMAND(ID_REQUEST_ADD, &CCelsusView::OnRequestAdd)
	ON_COMMAND(ID_EDIT_PRIORITY_PICK, &CCelsusView::OnEditPriorityPick)
	ON_COMMAND(ID_EDIT_PRIORITY_ADD, &CCelsusView::OnEditPriorityAdd)
	ON_COMMAND(ID_EDIT_METHOD_PICK, &CCelsusView::OnEditMethodPick)
	ON_COMMAND(ID_EDIT_METHOD_ADD, &CCelsusView::OnEditMethodAdd)
	ON_COMMAND(ID_EDIT_STATUS_PICK, &CCelsusView::OnEditStatusPick)
	ON_COMMAND(ID_EDIT_STATUS_ADD, &CCelsusView::OnEditStatusAdd)
	ON_COMMAND(ID_REQUEST_MANUALCOMPLETE, &CCelsusView::OnRequestManualcomplete)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_MANUALCOMPLETE, &CCelsusView::OnUpdateRequestManualcomplete)
	ON_COMMAND(ID_REQUEST_HISTORY, &CCelsusView::OnRequestHistory)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_HISTORY, &CCelsusView::OnUpdateRequestHistory)
	ON_NOTIFY(LVN_KEYDOWN, IDC_LIST_REQUESTS, &CCelsusView::OnLvnKeydownListRequests)
	ON_NOTIFY(LVN_GETINFOTIP, IDC_LIST_REQUESTS, &CCelsusView::OnLvnGetInfoTipListRequests)
	ON_COMMAND(ID_FILE_LOGIN_AS, &CCelsusView::OnFileLoginAs)
	ON_COMMAND(ID_EDIT_COLLECTION_PICK, &CCelsusView::OnEditCollectionPick)
	ON_COMMAND(ID_EDIT_COLLECTION_ADD, &CCelsusView::OnEditCollectionAdd)
	ON_COMMAND(ID_ADMIN_DELETEREQUEST, &CCelsusView::OnAdminDeleterequest)
	ON_COMMAND(ID_REQUEST_NOTES, &CCelsusView::OnRequestNotes)
	ON_COMMAND(ID_SORT_INVOICED, &CCelsusView::OnSortInvoiced)
	ON_UPDATE_COMMAND_UI(ID_SORT_INVOICED, &CCelsusView::OnUpdateSortInvoiced)
	ON_NOTIFY(LVN_ODCACHEHINT, IDC_LIST_REQUESTS, &CCelsusView::OnLvnOdcachehintListRequests)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_SOURCE, &CCelsusView::OnUpdateRequestSource)
	ON_COMMAND(ID_REQUEST_SOURCE, &CCelsusView::OnRequestSource)
	ON_UPDATE_COMMAND_UI(ID_REQUEST_NOTES, &CCelsusView::OnUpdateRequestNotes)
	ON_COMMAND(ID_VIEW_SAVECOLUMNORDER, &CCelsusView::OnViewSavecolumnorder)	
	ON_COMMAND(ID_EDIT_COPY_REQUEST_ID, &CCelsusView::OnEditCopyitemid)
	ON_UPDATE_COMMAND_UI(ID_EDIT_COPY_REQUEST_ID, &CCelsusView::OnUpdateEditCopyitemid)
	ON_COMMAND(ID_VIEW_REQUESTWINDOW, &CCelsusView::OnViewRequestwindow)
	ON_UPDATE_COMMAND_UI(ID_VIEW_REQUESTWINDOW, &CCelsusView::OnUpdateViewRequestwindow)
	ON_COMMAND(ID_EXTERNALL_ILL_SEND_FILE, &CCelsusView::OnExternallIllSendFile)
	ON_COMMAND(ID_EXTERNAL_ILL_EDITUSER, &CCelsusView::OnExternalILLEditUser)
	ON_UPDATE_COMMAND_UI(ID_EXTERNAL_ILL_EDITUSER, &CCelsusView::OnUpdateExternalIllEdituser)
	ON_UPDATE_COMMAND_UI(ID_FILE_PROCESSASCOMPLETE, &CCelsusView::OnUpdateFileProcessascomplete)
	ON_COMMAND(ID_FILE_PROCESSASCOMPLETE, &CCelsusView::OnFileProcessascomplete)
	ON_COMMAND(ID_EDIT_ADVANCEDFIND, &CCelsusView::OnEditAdvancedfind)
	ON_COMMAND(ID_VIEW_LINKSLIST, &CCelsusView::OnViewLinkslist)
	ON_COMMAND(ID_USERSITE_PICK, &CCelsusView::OnUsersitePick)
	ON_COMMAND(ID_USERSITE_CURRENT, &CCelsusView::OnUsersiteCurrent)
	ON_UPDATE_COMMAND_UI(ID_USERSITE_CURRENT, &CCelsusView::OnUpdateUsersiteCurrent)
	ON_COMMAND(ID_VIEW_SOURCELINKSLIST, &CCelsusView::OnViewSourcelinkslist)
	ON_COMMAND(ID_SOURCE_OPENSOURCE, &CCelsusView::OnSourceOpensource)
	ON_COMMAND(ID_SOURCE_EDITSOURCE, &CCelsusView::OnSourceEditsource)
	ON_COMMAND(ID_VIEW_HISTORYTODAY, &CCelsusView::OnViewHistorytoday)
	ON_COMMAND(ID_EXTERNALILL_HISTORY, &CCelsusView::OnExternalillHistory)
	ON_COMMAND(ID_EXTERNALILL_FIND, &CCelsusView::OnExternalillFind)
	ON_COMMAND(ID_EDIT_ILL_PICK, &CCelsusView::OnEditIllPick)
	ON_COMMAND(ID_EDIT_ILL_ADD, &CCelsusView::OnEditIllAdd)
	ON_COMMAND(ID_INFORMATION_LOGIN_PAGE, &CCelsusView::OnInformationLoginPage)
	ON_COMMAND(ID_INFORMATION_NEWS_ITEM_MACRO, &CCelsusView::OnInformationNewsItemMacro)
	ON_COMMAND(ID_FILE_DIVERTREQUESTS, &CCelsusView::OnFileDivertrequests)
	END_MESSAGE_MAP()

// CCelsusView construction/destruction

CCelsusView::CCelsusView()
	: CFormView(CCelsusView::IDD)
{
	m_nStaffID = -1;
	m_bInitialized = FALSE;
	m_nCurrentRecord = 0;
	m_nRecordCount = 0;
	m_nCurrentLibrary = 0;
	m_nTicker = 0;
	m_nTickerMultiplier = 1;
	m_nFindTabIndex = -1;
	m_bTimerPaused = FALSE;
	m_bShowTimerCount = FALSE;
	m_nViewMode = 0;
	m_nPrintY = 0;
	m_nSortBy = SORT_NORMAL;
	m_bProcessComplete = FALSE;

	m_nLower = -1;
	m_nUpper = -1;
	m_nCacheFrom = -1;
	m_nCacheTo = -1;
	m_bResetCache = TRUE;
	m_bInitialNavigate = TRUE;

	m_pRequestViewDlg = NULL;

	// preferences
	m_nCurrentLibrary = 0;
	m_nCurrentSort = -1;
	m_bShowLibraryView = TRUE;
	m_bShowMyView = TRUE;
	m_bShowInProcessView = FALSE;
	m_bShowCurrentView = FALSE;
	m_bShowCompletedView = FALSE;
	m_bShowHoldView = FALSE;
	m_bShowTriage = FALSE;
	m_bShowHighlights = TRUE;
	m_bSortAscending = TRUE;
	m_bHighlightDuplicate = TRUE;
	m_bPrintFullCitation = FALSE;
	m_bBoldEmailOnPrint = TRUE;
	m_bEnableThumbnail = TRUE;
	m_bShowThumbnail = TRUE;
	m_bUsePrintTemplate = FALSE;
	m_bShowRequestWindow = FALSE;
	m_bProcessComplete = FALSE;
	m_nDefaultCollection = 0;
}

CCelsusView::~CCelsusView()
{
}

void CCelsusView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);

	DDX_Control(pDX, IDC_LIST_REQUESTS, m_ctrlRequestList);
	DDX_Control(pDX, IDC_TAB_CTRL, m_ctrlTabSelection);
	DDX_Control(pDX, IDC_EXPLORER_REQUESTER, m_wbRequester);
	DDX_Control(pDX, IDC_EXPLORER_INFORMATION, m_wbInformation);
	DDX_Control(pDX, IDC_EXPLORER_REQUEST, m_wbRequest);
}

BOOL CCelsusView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CCelsusView::OnInitialUpdate()
{
	// test system
	if( appConfig.m_General.bTestSystem )
	{
		if( AfxMessageBox( _T("This is a test and devlopment system only.\n\nDo you want to login?"), MB_YESNO ) == IDNO )
		{
			// close with error number
			PostQuitMessage( 2003 );
			return;
		}
	}

	// set database connecitons
	appConfig.m_SQL.SetConnection( appConfig.m_Database.szServer, appConfig.m_Database.szDatabase, appConfig.m_Database.szUID, appConfig.m_Database.szPWD );
	if( !appConfig.m_External.szServer.IsEmpty() )
	{
		appConfig.m_SQL.SetExternalConnection( appConfig.m_External.szServer, appConfig.m_External.szDatabase, appConfig.m_External.szUID, appConfig.m_External.szPWD );
	}

	// show logon dialog
	BOOL bLogon = FALSE;
	CDlgLogon dlgLogon;
	while( !bLogon )
	{
		// show logon dialog
		if( dlgLogon.DoModal() == IDOK )
		{
			STAFF_SET Staff;

			// check LDAP
			if( appConfig.m_LDAP.bUseLDAPLogons )
			{
				// get info
				LDAP_STAFF_INFO StaffInfo;
				if( !appConfig.GetLDAPStaff( appConfig.m_LDAP.szServer, dlgLogon.m_szUID, dlgLogon.m_szPWD, &StaffInfo) )
				{
					//try again
					bLogon = FALSE;
				}
				else
				{
					// auto add staff
					if( appConfig.m_LDAP.bAutoAddStaff )
					{
						// check if already there
						appConfig.m_SQL.GetStaffSet( &Staff, dlgLogon.m_szUID );
						// not found add
						if( Staff.m_id == -1 )
						{
							// set current and add
							appConfig.m_SQL.InitStaffSet( &Staff );

							Staff.m_name = StaffInfo.szLANID;
							Staff.m_email = StaffInfo.szEmail;
							Staff.m_phone = StaffInfo.szPhone;

							appConfig.m_SQL.SetStaffSet( &Staff, -1, TRUE );
						}
					}
					else
					{
						//staff description
						appConfig.m_SQL.GetStaffSet( &Staff, dlgLogon.m_szUID );
					}

					// check valid user name first
					if( Staff.m_id == -1 )
					{
						//try again
						bLogon = FALSE;
					}
					else
					{
						// verified
						bLogon = TRUE;
					}
				}
			}
			else
			{
				//staff description
				appConfig.m_SQL.GetStaffSet( &Staff, dlgLogon.m_szUID );

				// check valid user name first
				if( Staff.m_id == -1 )
				{
					//try again
					bLogon = FALSE;
				}
				else
				{
					// get password
					CString szHash;
					// convert for hash
					szHash = dlgLogon.m_szPWD;
					appConfig.Hash( &szHash );
					// check
					if( szHash == Staff.m_pwd )
					{
						// verified
						bLogon = TRUE;
					}
					else
					{
						//try again
						bLogon = FALSE;
					}
				}
			}
			// logon if everything checked out
			if( bLogon )
			{
				// set staff and library ID
				m_nStaffID = Staff.m_id;
				m_nCurrentLibrary = Staff.m_library_id;
				// global level
				appConfig.m_nStaffLevel = Staff.m_level;
				// set staff info
				m_StaffInfo.nStaffID = Staff.m_id;
				m_StaffInfo.nStaffLevel = Staff.m_level;
				m_StaffInfo.szStaffName = Staff.m_name;
				m_StaffInfo.szStaffEmail = Staff.m_email;
				m_StaffInfo.szStaffPhone = Staff.m_phone;
				m_StaffInfo.nLibraryID = Staff.m_library_id;
				// set tab views
				m_bShowLibraryView = Staff.m_show_library_view;
				m_bShowMyView = Staff.m_show_my_view;
				m_bShowInProcessView = Staff.m_show_process_view;
				m_bShowCurrentView = Staff.m_show_current_view;
				m_bShowCompletedView = Staff.m_show_completed_view;
				m_bShowHoldView = Staff.m_show_hold_view;
				// preferences
				m_bSortAscending = Staff.m_sort_ascending;
				m_bShowTriage = Staff.m_show_triage;
				m_bShowHighlights = Staff.m_show_highlights;
				m_bHighlightDuplicate = Staff.m_show_duplicates;
				m_bPrintFullCitation = Staff.m_print_full_request;
				m_bBoldEmailOnPrint = Staff.m_bold_email_print;
				m_bEnableThumbnail = Staff.m_enable_thumbnail;
				m_bUsePrintTemplate = Staff.m_use_print_template;
				m_nDefaultCollection = Staff.m_default_collection;
				// override printing
				if( Staff.m_print_per_page > 0 )
					appConfig.m_Printing.nRequestsPerPage = Staff.m_print_per_page;
				// set sort type
				if( m_bSortAscending )
					m_szSort += _T("requests.id ASC");
				else
					m_szSort += _T("requests.id DESC");

				// get local settings
				m_bProcessComplete = AfxGetApp()->GetProfileInt( _T("Settings"), _T("ProcessComplete"), 0 );
			}
			else
			{
				// show message
				AfxMessageBox( IDS_ERROR_LOGON, MB_ICONSTOP );
			}
		}
		else
		{
			// close with error number
			PostQuitMessage( 2002 );
			//((CMainFrame*)GetParentFrame())->PostMessage( WM_CLOSE );
			return;
		}
	}

	// disable my view
	if( appConfig.m_Options.bDisableMyView )
		m_bShowMyView = FALSE;

	// set login date
	appConfig.m_SQL.SetCurrentDateTime( CMySQLEx::staff, _T("date_login"), m_nStaffID );

	// get staff from DB
	GetStaff();
	//GetUsers();
	// get descriptions from DB
	GetDescriptions();
	// get libraries
	GetLibraries();
	// get collections
	GetCollections();
	// get priorities
	GetPriorities();
	// get methods
	GetMethods();
	// get statuses
	GetStatuses();

	// read formatted display files
	m_szRequestFile = appConfig.ReadFile( appConfig.m_General.szRequestFile );
	m_szInformationFile = appConfig.ReadFile( appConfig.m_General.szRequestNoteFile );
	m_szRequesterFile = appConfig.ReadFile( appConfig.m_General.szRequesterInfoFile );

	// set filter
	m_szFilter.Format( _T("requests.library_id = %ld  AND requests.status_id <= %d AND requests.staff_id <= 0"), m_nCurrentLibrary, STATUS_ID_PENDING );

	// update form view
	CFormView::OnInitialUpdate();

	// remove admin menu
	if( m_StaffInfo.nStaffLevel < STAFF_ADMIN )
	{
		CMainFrame *pMain = (CMainFrame*)AfxGetMainWnd();
		CMenu *pMenu = pMain->GetMenu();
		pMenu->EnableMenuItem( ADMIN_MENU_ITEM, MF_BYPOSITION | MF_DISABLED | MF_GRAYED );
	}
	// remove external ILL menu
	if( appConfig.m_Options.bDisableILL )
	{
		CMainFrame *pMain = (CMainFrame*)AfxGetMainWnd();
		CMenu *pMenu = pMain->GetMenu();
		pMenu->RemoveMenu( EXTERNAL_ILL_MENU_ITEM, MF_BYPOSITION );
	}

	// add user icons
	LoadItemIcons();

	// set extended styles
	m_ctrlRequestList.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_HEADERDRAGDROP );

	// add columns to request list
	m_ctrlRequestList.InsertColumn( COL_SCHEDULE, _T(""), LVCFMT_CENTER,  18, COL_SCHEDULE );
	m_ctrlRequestList.InsertColumn( COL_DELIVERY, _T(""), LVCFMT_CENTER, 18, COL_DELIVERY );
	m_ctrlRequestList.InsertColumn( COL_COLLECTION, _T(""), LVCFMT_CENTER, 18, COL_COLLECTION );	
	m_ctrlRequestList.InsertColumn( COL_ITEM, _T("Item ID"), LVCFMT_LEFT, 85, COL_ITEM );
	m_ctrlRequestList.InsertColumn( COL_DATE, _T("Date"), LVCFMT_LEFT, 90, COL_DATE );
	m_ctrlRequestList.InsertColumn( COL_DATE_HOLD, _T("Date Hold"), LVCFMT_LEFT, 90, COL_DATE_HOLD );
	m_ctrlRequestList.InsertColumn( COL_EMAIL, _T("EMail"), LVCFMT_LEFT,  200, COL_EMAIL );
	m_ctrlRequestList.InsertColumn( COL_LOCATION, _T("Location"), LVCFMT_LEFT, 100, COL_LOCATION );
	m_ctrlRequestList.InsertColumn( COL_UID, _T("Identifier"), LVCFMT_LEFT, 100, COL_UID );
	m_ctrlRequestList.InsertColumn( COL_DETAIL, _T("Detail"), LVCFMT_LEFT, 300, COL_DETAIL );	
	m_ctrlRequestList.InsertColumn( COL_PROJECT, _T("Project"), LVCFMT_LEFT, 100, COL_PROJECT );
	m_ctrlRequestList.InsertColumn( COL_SOURCE, _T("Source"), LVCFMT_LEFT, 200, COL_SOURCE );
	m_ctrlRequestList.InsertColumn( COL_WORKER, _T("Staff"), LVCFMT_LEFT, 0, COL_WORKER );
	m_ctrlRequestList.InsertColumn( COL_LIBRARY, _T("Library"), LVCFMT_LEFT, 0, COL_LIBRARY );
	m_ctrlRequestList.InsertColumn( COL_STATUS, _T("Status"), LVCFMT_LEFT, 0, COL_STATUS );

	// hide project
	if( appConfig.m_Options.bDisableProject )
		m_ctrlRequestList.SetColumnWidth( COL_PROJECT, 0 );

	// get column order
	GetColumnOrder();

	// navigate to show browser window
	m_wbRequest.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
	m_wbInformation.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
	m_wbRequester.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );

	// set window posistion
	CRect rectScreen( 0,0,0,0 );
	CRect rectWindow( 0,0,0,0 );
	appConfig.ReadWindowLocation( _T("Main_Window"), &rectWindow );
	rectWindow.NormalizeRect();
	::GetWindowRect( ::GetDesktopWindow(), &rectScreen );
	// verify window location
	if( !rectWindow.IsRectEmpty() &&
		rectWindow.left > 0 &&
		rectWindow.top > 0 &&
		rectWindow.left < rectScreen.right && 
		rectWindow.top < rectScreen.bottom )
	{
		// position window
		CalcWindowRect( &rectWindow );
		((CMainFrame*)GetParentFrame())->SetWindowPos( NULL, rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(), SWP_NOZORDER | SWP_NOREDRAW );
	}
	else if( appConfig.m_General.nStartHeight > 0 && appConfig.m_General.nStartWidth > 0 )
	{
		// position window
		CRect rect( 0, 0, appConfig.m_General.nStartWidth, appConfig.m_General.nStartHeight );
		CalcWindowRect( &rect );
		((CMainFrame*)GetParentFrame())->SetWindowPos( NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW );
	}

	// set images for tabs
	m_ctrlTabSelection.SetImageList( &m_ilImages );

	// set tab view
	ShowTabView( TAB_LIBRARY );

	// set document title
	CString szTitle;
	szTitle.Format( _T("[%s] Logged on %s as %s"), appConfig.m_General.szLocation, appConfig.m_Database.szServer, m_StaffInfo.szStaffName );
	GetDocument()->SetTitle( szTitle );

	// set status
	CString szText;
	INT nSelected = m_ctrlRequestList.GetSelectedCount();
	szText.Format( _T("Ready  [ %d of %d Selected ]"), nSelected, m_nRecordCount );
	((CMainFrame*)GetParentFrame())->SetStatus( 0, szText );

	// set ticker
	m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;
	// start timer
	SetTimer( ID_TIMER, 1000, NULL );

	// size controls
	SizeControls( -1, -1 );
}


// CCelsusView diagnostics

#ifdef _DEBUG
void CCelsusView::AssertValid() const
{
	CFormView::AssertValid();
}

void CCelsusView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CCelsusDoc* CCelsusView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCelsusDoc)));
	return (CCelsusDoc*)m_pDocument;
}
#endif //_DEBUG


// CCelsusView message handlers

void CCelsusView::OnSize(UINT nType, int cx, int cy)
{
	CFormView::OnSize(nType, cx, cy);

	// size controls
	SizeControls( cx, cy );
}

void CCelsusView::OnContextMenu(CWnd* pWnd, CPoint point)
{
	// check for slection
	if( m_ctrlRequestList.GetSelectedCount() < 1 )
		return;

	// Kill timer
	PauseTimer();

	// get tab view
	GetTabView();

	// get column
	INT nSubItemId = GetColumnID();

	// save current
	m_nCurrentRecord = m_ctrlRequestList.GetSelectionMark();

	CMenu menu;
	if( m_nViewMode == TAB_COMPLETE )
	{
		// load complete tab context
		if( menu.LoadMenu( IDR_MENU_CONTEXT_COMPLETE ))
		{
			CMenu* pPopup = menu.GetSubMenu(0);
			CmdRouteMenu( this, pPopup );
			INT nCmd = pPopup->TrackPopupMenu( TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, this );
			// check return value
			if( !nCmd )
				return;
			// send command message
			::SendMessage( m_hWnd, WM_COMMAND, nCmd, NULL );
		}
	}
	else if( m_nViewMode == TAB_FIND || m_nViewMode == TAB_ARTICLES )
	{
		// load complete tab context
		if( menu.LoadMenu( IDR_MENU_CONTEXT_SEARCH ))
		{
			CMenu* pPopup = menu.GetSubMenu(0);
			CmdRouteMenu( this, pPopup );
			INT nCmd = pPopup->TrackPopupMenu( TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, this );
			// check return value
			if( !nCmd )
				return;
			// send command message
			::SendMessage( m_hWnd, WM_COMMAND, nCmd, NULL );
		}
	}
	else
	{
		// get request
		REQUEST_DISPLAY_SET currentRequest;
		m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );

		// load other tab context
		if( menu.LoadMenu( IDR_MENU_LIST_CONTEXT ))
		{
			// get context menu
			CMenu *pPopup = menu.GetSubMenu(0);

			// add source editing
			if( nSubItemId == COL_SOURCE && !currentRequest.m_source_link.IsEmpty() )
			{
				pPopup->InsertMenu( 0, MF_BYPOSITION, MF_SEPARATOR );				
				pPopup->InsertMenu( 0, MF_BYPOSITION, ID_SOURCE_EDITSOURCE, _T("Edit Source URL...") );
				pPopup->InsertMenu( 0, MF_BYPOSITION, ID_SOURCE_OPENSOURCE, _T("Open Source URL...") );
			}

			// disable my view
			if( appConfig.m_Options.bDisableMyView )
				pPopup->RemoveMenu( ID_REQUEST_CLAIM, MF_BYCOMMAND );

			CmdRouteMenu( this, pPopup );
			INT nCmd = pPopup->TrackPopupMenu( TPM_RETURNCMD | TPM_LEFTALIGN, point.x, point.y, this );
			// check return value
			if( !nCmd )
				return;
			// send command message
			::SendMessage( m_hWnd, WM_COMMAND, nCmd, NULL );
		}
	}
	// start timer
	PauseTimer( FALSE );
}

// CLIttsView functions
BOOL CCelsusView::SizeControls(INT cx, INT cy)
{
	// check if we are created
	if( m_ctrlRequestList.GetSafeHwnd() )
	{
		CRect rectClient;
		// get client rect
		GetClientRect( rectClient );
		// move list control
		m_ctrlRequestList.SetWindowPos( NULL, rectClient.left + 10, rectClient.top + 35, rectClient.Width() - 20, rectClient.Height() - 245, SWP_NOZORDER );
		// move tab contrl
		GetDlgItem( IDC_TAB_CTRL )->SetWindowPos( NULL, rectClient.left + 10, rectClient.top + 10, rectClient.Width() - 18, 35, SWP_NOZORDER );		
		// move citation detail
		GetDlgItem( IDC_EXPLORER_REQUEST )->SetWindowPos( NULL, rectClient.left + 10, rectClient.bottom - 205, rectClient.Width() / 2 - 10, 140, SWP_NOZORDER );
		// move information
		GetDlgItem( IDC_EXPLORER_INFORMATION )->SetWindowPos( NULL, rectClient.Width() / 2, rectClient.bottom - 205, rectClient.Width() / 2 - 10, 140, SWP_NOZORDER );
		// move requester		
		GetDlgItem( IDC_EXPLORER_REQUESTER )->SetWindowPos( NULL, rectClient.left + 10, rectClient.bottom - 60, rectClient.Width() - 20, 55, SWP_NOZORDER );
	}
	return FALSE;
}

void CCelsusView::OnLvnOdcachehintListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLVCACHEHINT pCacheHint = reinterpret_cast<LPNMLVCACHEHINT>(pNMHDR);
	// set return
	*pResult = 0;

	m_nCacheFrom = pCacheHint->iFrom;
	m_nCacheTo = pCacheHint->iTo;

	// only use hints on complete
	if( m_nViewMode == TAB_COMPLETE )
		UpdateRequestArray(TRUE);

	//TRACE( _T("C %d - %d (%ld:%ld)\n"), m_nCacheFrom, m_nCacheTo, m_mRequestSet.GetCount(), (LONG)m_nRecordCount );
}

void CCelsusView::OnLvnGetdispinfoListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);

	// set result
	*pResult = 0;
    // Create a pointer to the item
    LV_ITEM* pItem = &(pDispInfo)->item;

    // Which item number?
    INT nItemId = pItem->iItem;

	// get request
	REQUEST_DISPLAY_SET currentRequest;
	if( !m_mRequestSet.Lookup( nItemId, currentRequest ))
		return;

	// check staff
	if( currentRequest.m_staff_id >= m_aStaffInfo.GetCount() )
		GetStaff();

	//TRACE( _T("D %d\n"), nItemId );

	// Does the list need text information?
	if( pItem->mask & LVIF_TEXT )
	{
		// set text
		CString szText;
		// set item id
		switch( pItem->iSubItem )		
		{
		case COL_SCHEDULE:
			break;			
		case COL_DELIVERY:
			break;
		case COL_COLLECTION:
			break;
		case COL_ITEM:
			szText.Format( _T("%.8ld"), currentRequest.m_id );
			break;
		case COL_DATE:
			// set date
			if( m_nViewMode == TAB_COMPLETE )
				szText.Format( _T("%s"), currentRequest.m_date_out.Format( _T("%d-%b-%Y") ));
			else
				szText = currentRequest.m_date_in.Format( appConfig.m_General.szDateFormat );
			break;
		case COL_DATE_HOLD:
			// set date
			if( currentRequest.m_date_hold.GetStatus() == COleDateTime::valid )
			{
				if( m_nViewMode == TAB_HOLD )
					szText.Format( _T("%s"), currentRequest.m_date_hold.Format( _T("%d-%b-%Y") ));
				else
					szText.Format( _T("%s"), currentRequest.m_date_hold.Format( _T("%d-%b-%Y %I:%M %p") ));
			}
			break;
		case COL_EMAIL:
			szText = currentRequest.m_users_email;
			break;
		case COL_LOCATION:
			if( !currentRequest.m_location.IsEmpty() )
			{
				szText = currentRequest.m_location;
			}
			else
			{
				if( appConfig.m_Options.bUseComapnyForLocation )
					szText = currentRequest.m_users_company;
				else
					szText = currentRequest.m_users_address1;
			}
			break;
		case COL_DETAIL:
			szText = currentRequest.m_request;
			szText = szText.Left( DETAIL_LENGTH );
			szText.Replace( _T("\n"), _T(" ") );
			szText.Replace( _T("\r"), _T(" ") );
			szText.Replace( _T("\t"), _T(" ") );
			break;
		case COL_UID:
			szText = currentRequest.m_uid;
			break;
		case COL_PROJECT:
			szText = currentRequest.m_project;
			break;
		case COL_SOURCE:
			szText = currentRequest.m_source;
			szText.Replace( _T("\n"), _T(" ") );
			szText.Replace( _T("\r"), _T(" ") );
			szText.Replace( _T("\t"), _T(" ") );
			break;
		case COL_WORKER:
			if( currentRequest.m_staff_id > 0 )
				if( m_aStaffInfo.GetCount() >= currentRequest.m_staff_id )
					szText = m_aStaffInfo.GetAt( currentRequest.m_staff_id ).szStaffName;
			break;
		case COL_LIBRARY:
			szText = m_szaLibrary.GetAt( currentRequest.m_library_id );
			break;
		case COL_STATUS:
			if( m_nViewMode == TAB_HOLD )
				szText.Format( _T("[%ld] %s"), currentRequest.m_status_id, m_aStatus.GetAt( currentRequest.m_status_id ).szExplanation );
			else
				szText = m_szaStatus.GetAt( currentRequest.m_status_id );
			break;
		}
		//Copy the text to the LV_ITEM structure
		//Maximum number of characters is in pItem->cchTextMax
		lstrcpyn( pItem->pszText, szText, pItem->cchTextMax );
	}

	// Does the list need image information?
	if( pItem->mask & LVIF_IMAGE ) 
	{
		// insert image
		INT nImage = GetItemImage( nItemId, pItem->iSubItem );
		// set image
		if( nImage >= 0 )
			pItem->iImage = nImage;
	}

	// set status
	CString szText;
	INT nSelected = m_ctrlRequestList.GetSelectedCount();
	szText.Format( _T("Ready  [ %d of %d Selected ]"), nSelected, m_nRecordCount );
	((CMainFrame*)GetParentFrame())->SetStatus( 0, szText );

	// return
	*pResult = CDRF_DODEFAULT;
}

void CCelsusView::OnNMCustomdrawListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
	// TODO: Add your control notification handler code here
	
	// get item
	LPNMLVCUSTOMDRAW pLVCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);	
	// set default
	*pResult = CDRF_DODEFAULT;

	// do draw stage
	switch( pLVCD->nmcd.dwDrawStage )
	{
	case CDDS_PREPAINT:
		{
			// set to notify draw item
			*pResult |= CDRF_NOTIFYITEMDRAW;
		}
		break;

	case CDDS_ITEMPREPAINT:
		{
			// set to notify pre paint sub item
			*pResult |= CDRF_NOTIFYSUBITEMDRAW;
		}
		break;

	case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
		{				
			INT nItemId = static_cast<int>( pLVCD->nmcd.dwItemSpec );
			INT nWeight = FW_NORMAL;
			BOOL bItalic = FALSE;
			BOOL bUnderline = FALSE;
			COLORREF clrText = RGB( 0x00, 0x00, 0x00 ), clrTextBk = RGB( 0xff, 0xff, 0xff );

			// default colors
			pLVCD->clrText = clrText;
			pLVCD->clrTextBk = clrTextBk;

			// set colors
			if( GetItemHighlight( nItemId, pLVCD->iSubItem, &clrText, &clrTextBk, &nWeight, &bItalic, &bUnderline ))
			{
				pLVCD->clrText = clrText;
				pLVCD->clrTextBk = clrTextBk;
			}
			// check for bold				
			if(( nWeight != FW_NORMAL ) || bItalic || bUnderline )
			{
				CFont fntFont;
				LOGFONT lfFont;
				m_ctrlRequestList.GetFont()->GetLogFont( &lfFont );
				// Set font style
				lfFont.lfWeight = nWeight;
				lfFont.lfItalic = bItalic;
				lfFont.lfUnderline = bUnderline;
				// Create a new font
				fntFont.CreateFontIndirect( &lfFont );
				// Select font
				SelectObject( pLVCD->nmcd.hdc, fntFont );
				// return new font
				*pResult |= CDRF_NEWFONT;
			}
			// check for tab sort
			if( pLVCD->iSubItem == m_nCurrentSort )
				pLVCD->clrTextBk = appConfig.m_Colors.dwSortHighlight;

			// set result for post paint
			if( pLVCD->nmcd.uItemState & CDIS_FOCUS )
				*pResult |= CDRF_NOTIFYPOSTPAINT;
		}
		break;

	case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
		{				
			// get image and draw it
			INT nItemId = static_cast<int>( pLVCD->nmcd.dwItemSpec );
			INT nImage = GetItemImage( nItemId, pLVCD->iSubItem );
			if( nImage >= 0 )
			{
				CRect rcIcon;
				CDC*  pDC = CDC::FromHandle( pLVCD->nmcd.hdc );
				// Get the rect that holds the item's icon.
				m_ctrlRequestList.GetSubItemRect( nItemId, pLVCD->iSubItem, LVIR_ICON, rcIcon );					
				// Draw the icon.					
				m_ilImages.Draw( pDC, nImage, rcIcon.TopLeft(), ILD_TRANSPARENT );					
				// skip default
				*pResult = CDRF_SKIPDEFAULT;
			}
		}
		break;
	}
}

void CCelsusView::OnLvnItemchangedListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

	// get new selection
	if( pNMLV->uNewState & LVIS_SELECTED )
	{
		if( m_nRecordCount >= 0 )
		{
			// set current record
			m_nCurrentRecord = pNMLV->iItem;
			// update request detail
			UpdateRequestDetail();
		}
		//TRACE( _T("Item Change: %d\n"), pNMLV->iItem );
	}
	//return result
	*pResult = 0;
}

void CCelsusView::OnNMClickListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

	// set status
	CString szText;
	szText.Format( _T("Ready  [ %d of %d Selected ]"), m_ctrlRequestList.GetSelectedCount(), m_nRecordCount );
	((CMainFrame*)GetParentFrame())->SetStatus( 0, szText );

	// return result
	*pResult = 0;
}

void CCelsusView::OnTcnSelchangeTabCtrl(NMHDR *pNMHDR, LRESULT *pResult)
{
	CWaitCursor wait;
	LVCOLUMN col;
	col.mask = LVCF_WIDTH;

	//TRACE( _T("Changing Tab\n") );

	// delete list
	m_ctrlRequestList.DeleteAllItems();

	// reset optional sort
	SetTabTitle( m_nViewMode, NULL, TRUE );

	// change view mode
	GetTabView();

	// remove search tab
	if( m_nFindTabIndex >= 0 )
	{
		m_ctrlTabSelection.DeleteItem( m_nFindTabIndex );
		m_nFindTabIndex = -1;
	}

	// reset ticker
	m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

	// set header information
	HDITEM hdi;
	CHeaderCtrl *pHeader = m_ctrlRequestList.GetHeaderCtrl();
	ASSERT( pHeader );
	if( pHeader )
	{
		memset( &hdi, NULL, sizeof( HDITEM ));
		pHeader->GetItem( m_nCurrentSort, &hdi );
		hdi.mask |= HDI_FORMAT;
		hdi.fmt |= HDF_STRING;
		pHeader->SetItem( m_nCurrentSort, &hdi );
		m_nCurrentSort = -1;
		// set sort type
		if( m_nViewMode == TAB_COMPLETE )
			m_szSort = _T("requests.date_out DESC");
		else
		{
			m_szSort = _T("requests.id");
			if( m_bSortAscending )
				m_szSort += _T(" ASC");
			else
				m_szSort += _T(" DESC");
		}
	}
	// set tab view
	SetTabView( m_nViewMode );
	// set result
	*pResult = 0;
}

void CCelsusView::OnHdnItemclickListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMHEADER pNMLV = reinterpret_cast<LPNMHEADER>(pNMHDR);

	// kill the timer
	PauseTimer();

	HDITEM hdi;
	CHeaderCtrl *pHeader = m_ctrlRequestList.GetHeaderCtrl();
	ASSERT( pHeader );

	// reset ticker
	m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

	// toggle sort
	if( m_nCurrentSort == pNMLV->iItem )
		m_bSortAscending = !m_bSortAscending;
	else
	{
		// set sort type
		m_bSortAscending = TRUE;
		// set header information
		memset( &hdi, NULL, sizeof( HDITEM ));
		pHeader->GetItem( m_nCurrentSort, &hdi );
		hdi.mask |= HDI_FORMAT;
		hdi.fmt |= HDF_STRING;
		pHeader->SetItem( m_nCurrentSort, &hdi );
	}
	// set current sort
	m_nCurrentSort = pNMLV->iItem;
	switch( m_nCurrentSort )
	{
	case COL_SCHEDULE:
		if( m_nViewMode == TAB_HOLD )
			m_szSort = _T("requests.status_id");
		else
			m_szSort = _T("requests.priority_id");
		break;
	case COL_DELIVERY:
		m_szSort = _T("requests.method_id");
		break;
	case COL_COLLECTION:
		m_szSort = _T("requests.collection_id");
		break;
	case COL_ITEM:
		m_szSort = _T("requests.id");
		break;
	case COL_DATE:
		if( m_nViewMode == TAB_COMPLETE )
			m_szSort = _T("requests.date_out");
		else if( m_nViewMode == TAB_HOLD )
			m_szSort = _T("requests.date_hold");
		else
			m_szSort = _T("requests.date_in");
		break;
	case COL_EMAIL:
		m_szSort = _T("users.email");
		break;
	case COL_LOCATION:
		if( appConfig.m_Options.bUseComapnyForLocation )
			m_szSort = _T("users.company");
		else
			m_szSort = _T("users.address1");
		break;
	case COL_DETAIL:
		m_szSort = _T("requests.request");
		break;
	case COL_UID:
		m_szSort = _T("requests.uid");
		break;
	case COL_PROJECT:
		m_szSort = _T("requests.project");
		break;
	case COL_SOURCE:
		m_szSort = _T("requests.source");
		break;
	case COL_WORKER:
		m_szSort = _T("requests.staff_id");
		break;
	case COL_LIBRARY:
		m_szSort = _T("requests.library_id");
		break;
	case COL_STATUS:
		m_szSort = _T("requests.status_id");
		break;
	default:
		*pResult = 0;
		return;
	}

	// set sort type
	if( m_bSortAscending )
		m_szSort += _T(" ASC");
	else
		m_szSort += _T(" DESC");

	// set header information
	if( m_nCurrentSort > 1 )
	{
		memset( &hdi, NULL, sizeof( HDITEM ));
		pHeader->GetItem( m_nCurrentSort, &hdi );
		hdi.mask |= HDI_FORMAT;
		if( m_bSortAscending )
			hdi.fmt |= HDF_STRING | HDF_SORTUP;
		else
			hdi.fmt |= HDF_STRING | HDF_SORTDOWN;
		pHeader->SetItem( m_nCurrentSort, &hdi );
	}
	
	// reset optional sort
	SetTabTitle( GetTabView(), NULL, TRUE );
	// refresh
	RefreshList( TRUE );
	// retrun
	*pResult = 0;
	// start the timer
	PauseTimer( FALSE );
}

void CCelsusView::OnLvnKeydownListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLVKEYDOWN pLVKeyDown = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);
	// set default action
	*pResult = 0;

	// check for 0 key
	if( pLVKeyDown->wVKey >= 48 && pLVKeyDown->wVKey <= 57 )
	{
		REQUEST_DISPLAY_SET currentRequest;
		// show locate dialog
		CDlgLocateRequest dlgLocate;
		if( dlgLocate.DoModal() == IDOK )
		{
			BOOL bFound = FALSE;
			LONG nCurrent = 0;
			LONG nItemFound = 0;

			TRACE(_T("Keydown: %s\n"), dlgLocate.m_szRequest);
			LONG nRequestID = _tstol( dlgLocate.m_szRequest );

			// get current
			nCurrent = m_ctrlRequestList.GetSelectionMark();
			// start from begining
			for( ULONG nCount = 0; nCount < m_nRecordCount; nCount++ )
			{
				// get item
				m_mRequestSet.Lookup( nCount, currentRequest );
				// find
				if( currentRequest.m_id == nRequestID )
				{
					// save item number
					nItemFound = nCount;
					// found
					bFound = TRUE;
					// remove hightlight
					POSITION pos = NULL;
					pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
					while( pos )
					{
						LONG nIndex = m_ctrlRequestList.GetNextSelectedItem( pos );
						m_ctrlRequestList.SetItemState( nIndex, NULL, LVIS_SELECTED | LVIS_FOCUSED );
					}
					// hightlight
					m_ctrlRequestList.SetSelectionMark( nCount );
					m_ctrlRequestList.SetItemState( nCount, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
					m_ctrlRequestList.EnsureVisible( nCount, FALSE );
					break;
				}
			}
			// move back to current
			if( !bFound )
			{
				// move to record
				m_nCurrentRecord = nCurrent;
				// play sound
				PlaySound ( (LPCTSTR)SND_ALIAS_SYSTEMEXCLAMATION, NULL, SND_ALIAS_ID | SND_NOSTOP | SND_ASYNC );
				// show message box
				AfxMessageBox( IDS_ERROR_REQUEST_NOT_FOUND, MB_OK | MB_ICONEXCLAMATION );
			}
			else
			{
				// set current
				m_nCurrentRecord = nItemFound;
				// get item
				m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
				// check tab and process				
				if( m_nViewMode == TAB_PROCESS || m_nViewMode == TAB_WORKER || m_nViewMode == TAB_FIND )
				{
					// process
					if( currentRequest.m_staff_id > 0 && currentRequest.m_status_id == STATUS_ID_IN_PROCESS )
						OnRequestProcess();
				}
			}
			// return TRUE to prevent default handilng
			*pResult = TRUE;
		}
	}
}

void CCelsusView::OnLvnOdfinditemListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	// pNMHDR has information about the item we should find
    // In pResult we should save which item that should be selected
	LPNMLVFINDITEM pFindInfo = reinterpret_cast<LPNMLVFINDITEM>(pNMHDR);

    /*
		pFindInfo->iStart is from which item we should search.
		We search to bottom, and then restart at top and will stop
		at pFindInfo->iStart, unless we find an item that match
	*/

    // Set the default return value to -1 that means we didn't find any match.
    *pResult = -1;

    //Is search NOT based on string?
    if(( pFindInfo->lvfi.flags & LVFI_STRING ) == 0 )
    {
        //This will probably never happend...
        return;
    }

    //This is the string we search for
	CString szSearch = pFindInfo->lvfi.psz;

    INT startPos = pFindInfo->iStart;
    //Is startPos outside the list (happens if last item is selected)
    if( startPos >= m_ctrlRequestList.GetItemCount() )
        startPos = 0;

	TRACE(_T("Find %s on %d\n"), szSearch, m_nCurrentSort);

	REQUEST_DISPLAY_SET currentRequest;
	ULONG currentPos = startPos;
	INT nColumn = m_nCurrentSort;

	// set for COL_ITEM if first character is 0
	if( szSearch.Left( 1 ) == _T("0") )
	{
		nColumn = COL_ITEM;
	}
	
	// search
    do
    {
		// get record
		m_mRequestSet.Lookup( currentPos, currentRequest );

		// find in column
		switch( nColumn )
		{
		case COL_SCHEDULE:
			break;
		case COL_DELIVERY:
			break;
		case COL_COLLECTION:
			break;
		case COL_ITEM:
			{
				// search the item column
				if( _tstol( szSearch ) == currentRequest.m_id )
				{
					//Select this item and stop search.
					*pResult = currentPos;
					return;
				}
			}
			break;
		case COL_DATE:
			// search the date column
			if( szSearch.CompareNoCase( currentRequest.m_date_in.Format( appConfig.m_General.szDateFormat ).Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_EMAIL:
			// search the email column
			if( szSearch.CompareNoCase( currentRequest.m_users_email.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_LOCATION:
			// search the location column
			if( szSearch.CompareNoCase( currentRequest.m_users_company.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_DETAIL:
			// search the citation column
			if( szSearch.CompareNoCase( currentRequest.m_request.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_UID:
			// search the citation column
			if( szSearch.CompareNoCase( currentRequest.m_uid.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_PROJECT:
			// search the citation column
			if( szSearch.CompareNoCase( currentRequest.m_project.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_SOURCE:
			// search the citation column
			if( szSearch.CompareNoCase( currentRequest.m_source.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_WORKER:
			// search the worker column
			if( szSearch.CompareNoCase( m_aStaffInfo.GetAt( currentRequest.m_staff_id ).szStaffEmail.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		case COL_LIBRARY:
			// search the library column
			if( szSearch.CompareNoCase( m_szaLibrary.GetAt( currentRequest.m_library_id ).Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		default:
			// search the email column
			if( szSearch.CompareNoCase( currentRequest.m_users_email.Left( szSearch.GetLength() )) == 0 )
			{
				//Select this item and stop search.
				*pResult = currentPos;
				return;
			}
			break;
		}

        //Go to next item
        currentPos++;

        //Need to restart at top?
		if( currentPos >= m_nRecordCount )
            currentPos = 0;
    }
    //Stop if back to start
	while( currentPos != startPos );

	//// show message box
	//if( bRequest )
	//	AfxMessageBox( IDS_ERROR_REQUEST_NOT_FOUND, MB_OK | MB_ICONEXCLAMATION );
}

void CCelsusView::OnNMDblclkListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);

	LRESULT Result = S_OK;

	// get column
	INT nSubItemId = GetColumnID();

	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 && m_ctrlRequestList.GetSelectedCount() >= 1 )
	{
		// get current tab
		GetTabView();

		//	TAB_LIBRARY, TAB_PROCESS, TAB_WORKER, TAB_ARTICLES, TAB_COMPLETE, TAB_FIND

		// process file
		switch( m_nViewMode )
		{
			case TAB_LIBRARY:
				Result = S_FALSE;
				// check for link
				if( nSubItemId == COL_DETAIL )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( currentRequest.m_webcheck < 1 && !appConfig.GetIDFromRequest( currentRequest.m_request ).IsEmpty() )
						OnRequestCheckonline();
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_SOURCE )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						ShellExecute( m_hWnd, NULL, currentRequest.m_source_link, NULL, NULL, SW_SHOWNORMAL );
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_UID )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						OnRequestSendlink();
					else
						OnRequestEdit();
					break;
				}
				else
				{
					OnRequestEdit();
				}
				break;
			case TAB_HOLD:
				Result = S_FALSE;
				// check for link
				if( nSubItemId == COL_DETAIL )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( currentRequest.m_webcheck < 1 && !appConfig.GetIDFromRequest( currentRequest.m_request ).IsEmpty() )
						OnRequestCheckonline();
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_SOURCE )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						ShellExecute( m_hWnd, NULL, currentRequest.m_source_link, NULL, NULL, SW_SHOWNORMAL );
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_UID )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						OnRequestSendlink();
					else
						OnRequestEdit();
					break;
				}
				else
				{
					OnRequestEdit();
				}
				break;
			case TAB_PROCESS:
				Result = S_FALSE;
				// check for link
				if( nSubItemId == COL_SOURCE )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						ShellExecute( m_hWnd, NULL, currentRequest.m_source_link, NULL, NULL, SW_SHOWNORMAL );
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_UID )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						OnRequestSendlink();
					else
						OnRequestEdit();
					break;
				}
				else
				{
					OnRequestProcess();
				}
				break;
			case TAB_WORKER:
				Result = S_FALSE;
				// check for link
				if( nSubItemId == COL_DETAIL )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( currentRequest.m_webcheck < 1 && !appConfig.GetIDFromRequest( currentRequest.m_request ).IsEmpty() )
						OnRequestCheckonline();
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_SOURCE )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						ShellExecute( m_hWnd, NULL, currentRequest.m_source_link, NULL, NULL, SW_SHOWNORMAL );
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_UID )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						OnRequestSendlink();
					else
						OnRequestEdit();
					break;
				}
				else
				{
					OnRequestEdit();
				}
				break;
			case TAB_ARTICLES:
				Result = S_FALSE;
				// check for link
				if( nSubItemId == COL_DETAIL )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( currentRequest.m_webcheck < 1 && !appConfig.GetIDFromRequest( currentRequest.m_request ).IsEmpty() )
						OnRequestCheckonline();
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_SOURCE )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						ShellExecute( m_hWnd, NULL, currentRequest.m_source_link, NULL, NULL, SW_SHOWNORMAL );
					else
						OnRequestEdit();
					break;
				}
				else if( nSubItemId == COL_UID )
				{
					// get request
					REQUEST_DISPLAY_SET currentRequest;
					m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
					if( !currentRequest.m_source_link.IsEmpty() )
						OnRequestSendlink();
					else
						OnRequestEdit();
					break;
				}
				else
				{
					OnRequestEdit();
				}
				break;
			case TAB_COMPLETE:
				Result = S_FALSE;
				OnRequestEdit();
				break;
			case TAB_FIND:
				Result = S_FALSE;
				OnRequestEdit();
				break;
		}
	}

	// return result
	*pResult = Result;
}

void CCelsusView::OnLvnGetInfoTipListRequests(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMLVGETINFOTIP pGetInfoTip = reinterpret_cast<LPNMLVGETINFOTIP>(pNMHDR);
	// TODO: Add your control notification handler code here
	*pResult = 0;

	// pause the timer
	PauseTimer();

    // Which item number?
    INT nItemId = pGetInfoTip->iItem;

	// get request
	REQUEST_DISPLAY_SET currentRequest;
	m_mRequestSet.Lookup( nItemId, currentRequest );

	CString szText;

	// add date info
	COleDateTimeSpan t_index;
	t_index = COleDateTime::GetCurrentTime() - currentRequest.m_date_in;
	// set old
	if( t_index.GetTotalHours() > m_aPriority.GetAt( currentRequest.m_priority_id ).nInHours )
		szText += _T("PAST DUE\n");

	// set library
	szText += _T("Library: ");
	szText += m_szaLibrary.GetAt( currentRequest.m_library_id );
	if( m_aLibrary.GetAt( currentRequest.m_library_id ).nType & ID_PROBLEM_LIBRARY )
		szText += _T(" (PROBLEM)");
	szText += _T("\n");

	// priority
	szText += _T("Priority: ");
	szText += m_szaPriority.GetAt( currentRequest.m_priority_id );
	szText += _T("\n");

	// method
	szText += _T("Method: ");
	szText += m_szaMethod.GetAt( currentRequest.m_method_id );
	szText += _T("\n");

	// collection
	szText += _T("Collection: ");
	szText += m_szaCollection.GetAt( currentRequest.m_collection_id );
	szText += _T("\n");

	// status
	szText += _T("Status: ");
	szText += m_szaStatus.GetAt( currentRequest.m_status_id );
	szText += _T("\n");

	// staff
	szText += _T("Staff: ");
	if( m_aStaffInfo.GetAt( currentRequest.m_staff_id ).nStaffID > 0 )
		szText += m_aStaffInfo.GetAt( currentRequest.m_staff_id ).szStaffName;
	if( currentRequest.m_retain > 0 )
		szText += _T(" (RETAINED) ");
	szText += _T("\n");

	// maybe online
	if( currentRequest.m_webcheck & ID_CHECKED_ONLINE_LINK )
		szText += _T("Online: Request is available online\n");
	// dynamic check source
	else if( !currentRequest.m_source_link.IsEmpty() && currentRequest.m_status_id < STATUS_OFFSET_NA )
	{
		if( currentRequest.m_source_material == MATERIAL_ELECTRONIC_LICENSED )
			szText += _T("Online: Request maybe available online (licensed)\n");
		else if( currentRequest.m_source_material == MATERIAL_ELECTRONIC_FREE )
			szText += _T("Online: Request maybe available online (free)\n");
		else if( currentRequest.m_source_material == MATERIAL_ELECTRONIC_NOTFREE )
			szText += _T("Online: Request maybe available online (not free)\n");
		else
			szText += _T("Online: Request maybe available online\n");
	}

	// set tooltip
	_tcscpy_s( pGetInfoTip->pszText, INFOTIPSIZE, (LPCTSTR)szText );

	// save current
	m_nCurrentRecord = m_ctrlRequestList.GetSelectionMark();

	// start the timer
	PauseTimer( FALSE );
}

void CCelsusView::OnTimer(UINT_PTR nIDEvent)
{
	// check timer ID
	if( nIDEvent == ID_TIMER )
	{
		if( !m_bTimerPaused )
		{
			// updates request detail when first opened
			if( m_bInitialNavigate )
			{
				UpdateRequestDetail();
				m_bInitialNavigate = FALSE;
			}

			// show timer counter
			if( m_bShowTimerCount )
			{
				// set status
				CString szText;
				INT nSelected = m_ctrlRequestList.GetSelectedCount();
				szText.Format( _T("Ready  [ %d of %d Selected ]  Next query in (%d)"), nSelected, m_nRecordCount, m_nTicker );
				((CMainFrame*)GetParentFrame())->SetStatus( 0, szText );
			}
			// decrement timer
			m_nTicker--;
			// check ticker
			if( m_nTicker < 0 )
			{
				// reset ticker
				m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;
				// refresh data
				RefreshList();
			}
		}
	}
	CFormView::OnTimer(nIDEvent);
}

BOOL CCelsusView::PauseTimer(BOOL bPause)
{
	m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;
	m_bTimerPaused = bPause;
	return m_bTimerPaused;
}

void CCelsusView::OnEditCopy()
{
	// copy to clipboard
	DoClipboardOp( ID_EDIT_COPY );
}

void CCelsusView::OnEditCopyitemid()
{
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	CString szItemID;

	// loop through count
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	while( pos )
	{
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// get new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		// set the item ID
		if( szItemID.IsEmpty() )
			szItemID.Format( _T("%.8ld"), displayRequest.m_id );
		else
		{
			CString szTemp;
			szTemp.Format( _T("\r\n%.8ld"), displayRequest.m_id );
			szItemID += szTemp;
		}
	}

	// copy to clipboard
	HGLOBAL g = ::GlobalAlloc(GMEM_MOVEABLE, (szItemID.GetLength() + 1) * sizeof(TCHAR));
	if(g == NULL)
	{ /* alloc failed */
		ASSERT(FALSE);  // failed to allocate memory
		return;
	} /* alloc failed */

	LPTSTR p = (LPTSTR)::GlobalLock(g);
	if(p == NULL)
	{ /* lock failed */
		ASSERT(FALSE);
		return;
	} /* lock failed */

	StringCchCopy(p, szItemID.GetLength() + 1, (LPCTSTR)szItemID);

	::GlobalUnlock(g);

	if(!OpenClipboard())
	{ /* clipboard open failed */
		ASSERT(FALSE);
		GlobalFree(g);
		return;
	} /* clipboard open failed */

	if(!EmptyClipboard())
	{ /* empty failed */
		ASSERT(FALSE);
		GlobalFree(g);
		return;
	} /* empty failed */

#ifdef _UNICODE
#define CF_ CF_UNICODETEXT 
#else
#define CF_ CF_TEXT
#endif
	if(::SetClipboardData(CF_, g) == NULL)
	{ /* SetClipboardData failed */
		ASSERT(FALSE); //
		::CloseClipboard();
		::GlobalFree(g);
		return;
	} /* SetClipboardData failed */
	::CloseClipboard();
}

void CCelsusView::OnEditFindRequest()
{
	// kill timer
	PauseTimer();

	CDlgFindRequest dlgFindRequest;
	dlgFindRequest.m_nLibrary = m_nCurrentLibrary;

	// show dialog
	if( dlgFindRequest.DoModal() == IDOK )
	{
		// set column
		LVCOLUMN col;
		col.mask = LVCF_WIDTH;

		// add tab
		GetTabView();
		if( m_nViewMode != TAB_FIND )
			m_nFindTabIndex = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_FIND, _T("Find"), NULL, TAB_FIND );
		// switch to tab
		if( m_nFindTabIndex >= 0 )
			m_ctrlTabSelection.SetCurSel( m_nFindTabIndex );

		// show columns
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 90 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 180 );
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 90 );

		// set filter
		m_szFilter = dlgFindRequest.m_szFilter;

		// modfiy query time
		m_nTickerMultiplier = TICKER_MULTIPLIER;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;
		// update view
		RefreshList( TRUE );

		// show nothing found message
		if( m_nRecordCount < 1 )
			AfxMessageBox( _T("Search complete, no requests found.") );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditAdvancedfind()
{
	// kill timer
	PauseTimer();

	CDlgSearchRequest dlgFindRequest;
	dlgFindRequest.m_nLibrary = m_nCurrentLibrary;
	dlgFindRequest.m_pszaStatus = &m_szaStatus;
	dlgFindRequest.m_pszaLibrary = &m_szaLibrary;

	// show dialog
	if( dlgFindRequest.DoModal() == IDOK )
	{
		// set column
		LVCOLUMN col;
		col.mask = LVCF_WIDTH;

		// add tab
		GetTabView();
		if( m_nViewMode != TAB_FIND )
			m_nFindTabIndex = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_FIND, _T("Find"), NULL, TAB_FIND );
		// switch to tab
		if( m_nFindTabIndex >= 0 )
			m_ctrlTabSelection.SetCurSel( m_nFindTabIndex );

		// show columns
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 90 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 180 );
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 90 );

		// set filter
		m_szFilter = dlgFindRequest.m_szFilter;

		// modfiy query time
		m_nTickerMultiplier = TICKER_MULTIPLIER;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;
		// update view
		RefreshList( TRUE );

		// show nothing found message
		if( m_nRecordCount < 1 )
			AfxMessageBox( _T("Search complete, no requests found.") );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestRefresh()
{
	//BOOL bCtrl = FALSE;
	// Check to see if the CTRL key is pressed
	//bCtrl = (BOOL)GetAsyncKeyState( VK_CONTROL ) >> (( sizeof( SHORT ) * 8 ) - 1 );

	// refresh
	RefreshList( TRUE );
}

void CCelsusView::OnFileChangelibrary()
{
	// kill timer
	PauseTimer();

	CDlgChangeLibrary dlgChange;
	// set variables
	dlgChange.m_nStaffID = m_StaffInfo.nStaffID;
	dlgChange.m_nCurrentLibrary = m_nCurrentLibrary;
	// show dialog
	if( dlgChange.DoModal() == IDOK )
	{
		// set current
		m_nCurrentLibrary = dlgChange.m_nCurrentLibrary;
		// update tab
		ShowTabView( GetTabView() );
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnFileDivertrequests()
{
	// kill timer
	PauseTimer();

	CDlgChangeLibrary dlgDivert;
	// set variables
	dlgDivert.m_nStaffID = m_StaffInfo.nStaffID;
	dlgDivert.m_nCurrentLibrary = m_nCurrentLibrary;
	dlgDivert.m_nType = CDlgChangeLibrary::TYPE_DIVERT;
	// show dialog
	if( dlgDivert.DoModal() == IDOK )
	{
		// toggle library divert
		LIBRARY_LOOKUP Library;
		Library = m_aLibrary.GetAt( dlgDivert.m_nCurrentLibrary );
		Library.bDiverted = !Library.bDiverted;
		appConfig.m_SQL.SetDescriptionLibrary( &Library );
		// update library in array
		m_aLibrary.GetAt( dlgDivert.m_nCurrentLibrary ).bDiverted = Library.bDiverted;
		// update tab
		ShowTabView( GetTabView() );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnFilePrintselected()
{
	// kill the timer
	PauseTimer();

	// check for print template
	if( !appConfig.m_Printing.szRequestTemplate.IsEmpty() && m_bUsePrintTemplate )
	{
		CString szRequestsHTML;
		CString szHTMLRequest;
		INT nCount = 0;

		// read templates
		szHTMLRequest = appConfig.ReadFile( appConfig.m_Printing.szRequestTemplate );

		// loop through count
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();

		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;

		while( pos )
		{
			CString szHTML = szHTMLRequest;
			// get item
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// get request
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
			// format macros
			appConfig.FormatMacros( &szHTML, currentRequest.m_id );
			// add to request
			szRequestsHTML += szHTML;

			// check for page break
			nCount++;
			if( nCount > appConfig.m_Printing.nRequestsPerPage )
			{
				szRequestsHTML += appConfig.m_Printing.szTemplatePageBreak;
				nCount = 0;
			}
		}
		// print requests
		CDlgPreviewHTML dlgPreview;
		dlgPreview.m_bPrint = TRUE;
		dlgPreview.m_bPromptPrinter = TRUE;
		dlgPreview.m_bPrintPreview = appConfig.m_Printing.bPrintPreview;
		dlgPreview.m_szHTML = szRequestsHTML;
		// show message
		dlgPreview.DoModal();
		// update history
		appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Printed") );
	}
	else
	{
		CDC dc;
		DOCINFO di;
		CPrintInfo Info;
		INT nCount = 0;
		INT nPage = 1;
		INT nTotal = 3;
		BOOL bPrinted = FALSE;
		CPrintDialog printDlg(FALSE);

		// get printer
		if( printDlg.DoModal() == IDCANCEL )
			 return;

		// get CDC	
		HDC hdc = printDlg.CreatePrinterDC();
		if( !dc.Attach( hdc ))
		{
			AfxMessageBox(_T("No printer found!"));
			return;
		}
		// loop through count
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();

		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;

		if( pos )
		{
			// set printed
			bPrinted = TRUE;
			// set printing
			dc.m_bPrinting = TRUE;		
			// Initialise
			::ZeroMemory (&di, sizeof (DOCINFO));
			di.cbSize = sizeof (DOCINFO);
			di.lpszDocName = _T("Celsus");
			// Begin a new print job
			dc.StartDoc(&di);
			// Get the printing extents and store in the m_rectDraw field of a CPrintInfo object		
			INT maxw = dc.GetDeviceCaps(HORZRES);
			INT maxh = dc.GetDeviceCaps(VERTRES);
			Info.m_rectDraw.SetRect(0, 0, maxw, maxh);
			// check for receipt printer
			if( maxw < 2000 || m_bPrintFullCitation)
				nTotal = 1;
		}

		while( pos )
		{
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// get request
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

			// start page
			if( nCount < 1 )
			{
				dc.StartPage();    // begin new page
				Info.m_nCurPage = nPage;
			}
			// print request
			if( appConfig.PrintRequest( &dc, currentRequest.m_id, nCount ))
			{
				nCount++;		
			}
			if( nCount >= nTotal )
			{
				// restart count
				nCount = 0;
				// increment page
				nPage++;
				// clean up
				dc.EndPage();   // end page
			}
			// update history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Printed") );
		}
		// end a print job
		if( bPrinted )
			dc.EndDoc();
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnFileProcessascomplete()
{
	// toggle
	m_bProcessComplete = !m_bProcessComplete;

	// save local
	AfxGetApp()->WriteProfileInt( _T("Settings"), _T("ProcessComplete"), m_bProcessComplete );
}

void CCelsusView::OnFileLoginAs()
{
	// kill timer
	PauseTimer();

	// show logon dialog
	BOOL bLogon = FALSE;
	CDlgLogon dlgLogon;
	while( !bLogon )
	{
		// show logon dialog
		if( dlgLogon.DoModal() == IDOK )
		{
			//staff description
			STAFF_SET Staff;
			// check LDAP
			if( appConfig.m_LDAP.bUseLDAPLogons )
			{
				// get info
				LDAP_STAFF_INFO StaffInfo;
				if( !appConfig.GetLDAPStaff( appConfig.m_LDAP.szServer, dlgLogon.m_szUID, dlgLogon.m_szPWD, &StaffInfo) )
				{
					//try again
					bLogon = FALSE;
				}
				else
				{
					// auto add staff
					if( appConfig.m_LDAP.bAutoAddStaff )
					{
						// check if already there
						appConfig.m_SQL.GetStaffSet( &Staff, dlgLogon.m_szUID );
						// not found add
						if( Staff.m_id == -1 )
						{
							// set current and add
							appConfig.m_SQL.InitStaffSet( &Staff );

							Staff.m_name = StaffInfo.szLANID;
							Staff.m_email = StaffInfo.szEmail;
							Staff.m_phone = StaffInfo.szPhone;

							appConfig.m_SQL.SetStaffSet( &Staff, -1, TRUE );
						}
					}
					else
					{
						//staff description
						appConfig.m_SQL.GetStaffSet( &Staff, dlgLogon.m_szUID );
					}

					// check valid user name first
					if( Staff.m_id == -1 )
					{
						//try again
						bLogon = FALSE;
					}
					else
					{
						// verified
						bLogon = TRUE;
					}
				}
			}
			else
			{
				appConfig.m_SQL.GetStaffSet( &Staff, dlgLogon.m_szUID );

				// check valid
				if( Staff.m_id == -1 )
				{
					// close with error number
					AfxMessageBox( _T("ERROR: No staff logons found in database.") );
					//PostQuitMessage( 2002 );
					((CMainFrame*)GetParentFrame())->PostMessage( WM_CLOSE );
					return;
				}
				// get password
				CString szHash;
				// convert for hash
				szHash = dlgLogon.m_szPWD;
				appConfig.Hash( &szHash );
				// check
				if( szHash == Staff.m_pwd )
				{
					// set staff and library ID
					m_nStaffID = Staff.m_id;
					m_nCurrentLibrary = Staff.m_library_id;
					// global level
					appConfig.m_nStaffLevel = Staff.m_level;
					// set staff info
					m_StaffInfo.nStaffID = Staff.m_id;
					m_StaffInfo.nStaffLevel = Staff.m_level;
					m_StaffInfo.szStaffName = Staff.m_name;
					m_StaffInfo.szStaffEmail = Staff.m_email;
					m_StaffInfo.szStaffPhone = Staff.m_phone;
					m_StaffInfo.nLibraryID = Staff.m_library_id;
					// set tab views
					m_bShowLibraryView = Staff.m_show_library_view;
					m_bShowMyView = Staff.m_show_my_view;
					m_bShowInProcessView = Staff.m_show_process_view;
					m_bShowCurrentView = Staff.m_show_current_view;
					m_bShowCompletedView = Staff.m_show_completed_view;
					m_bShowHoldView = Staff.m_show_hold_view;
					// preferences
					m_bSortAscending = Staff.m_sort_ascending;
					m_bHighlightDuplicate = Staff.m_show_duplicates;
					m_bPrintFullCitation = Staff.m_print_full_request;
					m_bBoldEmailOnPrint = Staff.m_bold_email_print;
					m_bEnableThumbnail = Staff.m_enable_thumbnail;
					m_bUsePrintTemplate = Staff.m_use_print_template;
					// override printing
					if( Staff.m_print_per_page > 0 )
						appConfig.m_Printing.nRequestsPerPage = Staff.m_print_per_page;
					// logon ok
					bLogon = TRUE;
				}
				else
				{
					// show message
					AfxMessageBox( IDS_ERROR_LOGON, MB_ICONSTOP );
				}
			}
		}
		else
		{
			//bLogon = TRUE;
			return;
		}
	}
	// set login date
	appConfig.m_SQL.SetCurrentDateTime( CMySQLEx::staff, _T("date_login"), m_nStaffID );

	// remove admin menu
	if( m_StaffInfo.nStaffLevel < STAFF_ADMIN )
	{
		CMainFrame *pMain = (CMainFrame*)AfxGetMainWnd();
		CMenu *pMenu = pMain->GetMenu();
		pMenu->EnableMenuItem( ADMIN_MENU_ITEM, MF_BYPOSITION | MF_DISABLED | MF_GRAYED );
	}

	// set tab view
	ShowTabView( TAB_LIBRARY );

	// get current
	m_nCurrentRecord = m_ctrlRequestList.GetSelectionMark();

	// set document title
	CString szTitle;
	szTitle.Format( _T("[%s] Logged on %s as %s"), appConfig.m_General.szLocation, appConfig.m_Database.szServer, m_StaffInfo.szStaffName );
	GetDocument()->SetTitle( szTitle );

	// set status
	CString szText;
	INT nSelected = m_ctrlRequestList.GetSelectedCount();
	szText.Format( _T("Ready  [ %d of %d Selected ]"), nSelected, m_nRecordCount );
	((CMainFrame*)GetParentFrame())->SetStatus( 0, szText );

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditUsersPick()
{
	// kill timer
	PauseTimer();

	CDlgEditUser dlgEditUser;
	// show dialog
	if( dlgEditUser.DoModal() == IDOK )
	{
		// write history
		appConfig.UpdateUserHistory( dlgEditUser.m_nUserID, _T("Edited by staff") );
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditUsersCurrent()
{
	// kill timer
	PauseTimer();

	CDlgEditUser dlgEditUser;
	// set current
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	dlgEditUser.m_nUserID = currentRequest.m_user_id;

	// show dialog
	if( dlgEditUser.DoModal() == IDOK )
	{
		// write history
		appConfig.UpdateUserHistory( dlgEditUser.m_nUserID, _T("Edited by staff") );
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditUsersAdd()
{
	// kill timer
	PauseTimer();

	// add user
	if( appConfig.m_LDAP.bUseLDAPLogons )
	{
		CDlgAddLDAPUser dlgAddUser;
		if( dlgAddUser.DoModal() == IDOK )
		{
			// write history
			appConfig.UpdateUserHistory( dlgAddUser.m_nUserID, _T("Added by staff") );
			// refresh
			RefreshList( TRUE );
		}
	}
	else
	{
		CDlgEditUser dlgEditUser;
		// set add
		dlgEditUser.m_bAddUser = TRUE;
		// show dialog
		if( dlgEditUser.DoModal() == IDOK )
		{
			// write history
			appConfig.UpdateUserHistory( dlgEditUser.m_nUserID, _T("Added by staff") );
			// refresh
			RefreshList( TRUE );
		}
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditStaffPick()
{
	// kill timer
	PauseTimer();

	CDlgEditStaff dlgEditStaff;
	// show dialog
	if( dlgEditStaff.DoModal() == IDOK )
	{
		// get staff
		GetStaff();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditStaffCurrent()
{
	// kill timer
	PauseTimer();

	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

	if( currentRequest.m_staff_id < 1 )
	{
		AfxMessageBox( _T("Current request is not claimed by staff. Unable to edit current staff." ));
		return;
	}

	CDlgEditStaff dlgEditStaff;
	// set current
	dlgEditStaff.m_nStaffID = currentRequest.m_staff_id;
	// show dialog
	if( dlgEditStaff.DoModal() == IDOK )
	{
		// get staff
		GetStaff();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditStaffAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditStaff dlgEditStaff;
	// set add
	dlgEditStaff.m_bAddStaff = TRUE;
	// show dialog
	if( dlgEditStaff.DoModal() == IDOK )
	{
		// get staff
		GetStaff();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditLibraryPick()
{
	// kill timer
	PauseTimer();

	CDlgEditLibrary dlgEditLibrary;
	// set add
	dlgEditLibrary.m_bAddLibrary = FALSE;
	// show dialog
	if( dlgEditLibrary.DoModal() == IDOK )
	{
		// get libraries
		GetLibraries();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditLibraryAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditLibrary dlgEditLibrary;
	// set add
	dlgEditLibrary.m_bAddLibrary = TRUE;
	// show dialog
	if( dlgEditLibrary.DoModal() == IDOK )
	{
		// get libraries
		GetLibraries();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditCollectionPick()
{
	// kill timer
	PauseTimer();

	CDlgEditCollection dlgEditCollection;
	// set add
	dlgEditCollection.m_bAddCollection = FALSE;
	// show dialog
	if( dlgEditCollection.DoModal() == IDOK )
	{
		// get collections
		GetCollections();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditCollectionAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditCollection dlgEditCollection;
	// set add
	dlgEditCollection.m_bAddCollection = TRUE;
	// show dialog
	if( dlgEditCollection.DoModal() == IDOK )
	{
		// get collections
		GetCollections();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditPriorityPick()
{
	// kill timer
	PauseTimer();

	CDlgEditPriority dlgEditPriority;
	// set add
	dlgEditPriority.m_bAddPriority = FALSE;
	// show dialog
	if( dlgEditPriority.DoModal() == IDOK )
	{
		// get priorities
		GetPriorities();
		// add user icons
		LoadItemIcons();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditPriorityAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditPriority dlgEditPriority;
	// set add
	dlgEditPriority.m_bAddPriority = TRUE;
	// show dialog
	if( dlgEditPriority.DoModal() == IDOK )
	{
		// get priorities
		GetPriorities();
		// add user icons
		LoadItemIcons();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditMethodPick()
{
	// kill timer
	PauseTimer();

	CDlgEditMethod dlgEditMethod;
	// set add
	dlgEditMethod.m_bAddMethod = FALSE;
	// show dialog
	if( dlgEditMethod.DoModal() == IDOK )
	{
		// get priorities
		GetMethods();
		// add user icons
		LoadItemIcons();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditMethodAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditMethod dlgEditMethod;
	// set add
	dlgEditMethod.m_bAddMethod = TRUE;
	// show dialog
	if( dlgEditMethod.DoModal() == IDOK )
	{
		// get methods
		GetMethods();
		// add user icons
		LoadItemIcons();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditStatusPick()
{
	// kill timer
	PauseTimer();

	CDlgEditStatus dlgEditStatus;
	// set add
	dlgEditStatus.m_bAdd = FALSE;
	// show dialog
	if( dlgEditStatus.DoModal() == IDOK )
	{
		// get status
		GetStatuses();
		// add user icons
		LoadItemIcons();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditStatusAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditStatus dlgEditStatus;
	// set add
	dlgEditStatus.m_bAdd = TRUE;
	// show dialog
	if( dlgEditStatus.DoModal() == IDOK )
	{
		// get status
		GetStatuses();
		// add user icons
		LoadItemIcons();
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditIllPick()
{
	// kill timer
	PauseTimer();

	CDlgEditILL dlgEditILL;
	// set add
	dlgEditILL.m_bAdd = FALSE;
	// show dialog
	if( dlgEditILL.DoModal() == IDOK )
	{
	}
	// start timer
	PauseTimer( FALSE );
}


void CCelsusView::OnEditIllAdd()
{
	// kill timer
	PauseTimer();

	CDlgEditILL dlgEditILL;
	// set add
	dlgEditILL.m_bAdd = TRUE;
	// show dialog
	if( dlgEditILL.DoModal() == IDOK )
	{
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnExternalILLEditUser()
{
	// kill timer
	PauseTimer();

	CDlgEditExternalILL dlgILL;
	dlgILL.m_nStaffID = m_nStaffID;
	dlgILL.m_paStaffInfo = &m_aStaffInfo;
	if( dlgILL.DoModal() == IDOK )
	{
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnExternalillHistory()
{
	// kill timer
	PauseTimer();

	CDlgHistoryList HistoryDlg;
	// set varialbes
	HistoryDlg.m_nType = HistoryDlg.HISTORY_EXTERNAL_ILL;
	HistoryDlg.m_nStaffID = m_nStaffID;
	HistoryDlg.m_pszaStatus = &m_szaStatus;
	HistoryDlg.m_paStaffInfo = &m_aStaffInfo;
	// show dialog
	if( HistoryDlg.DoModal() == IDOK )
	{
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnExternalillFind()
{
	// kill timer
	PauseTimer();

	CDlgRequestFind dlgFind;
	dlgFind.m_szTitle = _T("Find External ILL History");
	if( dlgFind.DoModal() == IDOK )
	{
		CDlgHistoryList HistoryDlg;
		// set varialbes
		HistoryDlg.m_szFind = dlgFind.m_szFind;
		HistoryDlg.m_nType = HistoryDlg.HISTORY_EXTERNAL_ILL;
		HistoryDlg.m_nStaffID = m_nStaffID;
		HistoryDlg.m_pszaStatus = &m_szaStatus;
		HistoryDlg.m_paStaffInfo = &m_aStaffInfo;
		// show dialog
		if( HistoryDlg.DoModal() == IDOK )
		{
		}
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnInformationLoginPage()
{
	// open edit dialog
	CDlgEditHTML dlgEdit;
	// set type
	dlgEdit.m_nType = INFORMATION_LOIGN_PAGE;
	// show modal
	dlgEdit.DoModal();
}

void CCelsusView::OnInformationNewsItemMacro()
{
	// open edit dialog
	CDlgEditHTML dlgEdit;
	// set type
	dlgEdit.m_nType = INFORMATION_NEWS_ITEM_MACRO;
	// show modal
	dlgEdit.DoModal();
}

void CCelsusView::OnAdminDeleterequest()
{
	// warn admin
	CString szMessage;
	szMessage.Format( _T("WARNING: This will permanatly delete all %d selected request(s).\n\nAre you sure you want to continue?"), m_ctrlRequestList.GetSelectedCount() );
	if( AfxMessageBox( szMessage, MB_YESNO ) == IDNO )
		return;

	CDlgConfirm dlgConfirm;
	dlgConfirm.m_szAction = _T("This will permantly delete this requests.\n\nAre you sure you want to proceed?");
	if( dlgConfirm.DoModal() != IDOK )
		return;

	PauseTimer();

	LONG nID = -1;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	// loop through count
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	while( pos )
	{
		// set new posistion
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );		

		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		nID = currentRequest.m_id;

		// write history
		appConfig.UpdateRequestHistory( nID, m_nStaffID, currentRequest.m_status_id, _T("Deleted by Admin") );

		// remove row
		appConfig.m_SQL.RemoveRequest( nID );
	}
	// refresh list
	RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnEditPreferences()
{
	// kill timer
	PauseTimer();

	CDlgEditStaff dlgEditStaff;
	// set add
	dlgEditStaff.m_nStaffID = m_nStaffID;
	dlgEditStaff.m_bEditUser = TRUE;
	// show dialog
	if( dlgEditStaff.DoModal() == IDOK )
	{
		//staff description
		STAFF_SET Staff;
		appConfig.m_SQL.GetStaffSet( &Staff, m_nStaffID );

		// set staff and library ID
		m_nStaffID = Staff.m_id;
		m_nCurrentLibrary = Staff.m_library_id;
		// global level
		appConfig.m_nStaffLevel = Staff.m_level;
		// set staff info
		m_StaffInfo.nStaffID = Staff.m_id;
		m_StaffInfo.nStaffLevel = Staff.m_level;
		m_StaffInfo.szStaffName = Staff.m_name;
		m_StaffInfo.szStaffEmail = Staff.m_email;
		m_StaffInfo.szStaffPhone = Staff.m_phone;
		m_StaffInfo.nLibraryID = Staff.m_library_id;
		// set tab views
		m_bShowLibraryView = Staff.m_show_library_view;
		m_bShowMyView = Staff.m_show_my_view;
		m_bShowInProcessView = Staff.m_show_process_view;
		m_bShowCurrentView = Staff.m_show_current_view;
		m_bShowCompletedView = Staff.m_show_completed_view;
		m_bShowHoldView = Staff.m_show_hold_view;
		// preferences
		m_bSortAscending = Staff.m_sort_ascending;
		m_bShowTriage = Staff.m_show_triage;
		m_bShowHighlights = Staff.m_show_highlights;
		m_bHighlightDuplicate = Staff.m_show_duplicates;
		m_bPrintFullCitation = Staff.m_print_full_request;
		m_bBoldEmailOnPrint = Staff.m_bold_email_print;
		m_bEnableThumbnail = Staff.m_enable_thumbnail;
		m_bUsePrintTemplate = Staff.m_use_print_template;
		// override printing
		if( Staff.m_print_per_page > 0 )
			appConfig.m_Printing.nRequestsPerPage = Staff.m_print_per_page;
		// refresh
		ShowTabView( m_nViewMode );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnUsersitePick()
{
	CDlgPickUser dlgPickUser;
	if( dlgPickUser.DoModal() == IDOK )
	{
		CString szURL;
		CString szUserEmail;
		USER_SET User;

		// set user filter
		szUserEmail = dlgPickUser.m_szEmail;
		// get user set
		if( appConfig.m_SQL.GetUserSet( &User, szUserEmail ))
		{
			// check if external
			if( User.m_external )
			{
				// get external user link
				szURL = appConfig.m_External.szUserSite;
				if( appConfig.m_SQL.GetExternalUserID( &User, szUserEmail ))
				{
					CString szTemp;
					szTemp.Format( _T("%ld"), User.m_id );
					szURL.Replace( _T("(USERID)"), szTemp );
					szURL.Replace( _T("(USERPID)"), User.m_pwd );
				}
			}
			else
			{
				// get user link
				szURL = appConfig.m_General.szUserSite;
				// format user link
				appConfig.FormatMacros( &szURL, -1, m_nStaffID, -1, -1, User.m_id );
			}
			// open web browser
			ShellExecute( NULL, _T("open"), szURL, NULL, NULL, SW_SHOWNORMAL );
		}
	}
}

void CCelsusView::OnUsersiteCurrent()
{
	// check request
	if( m_nRecordCount < 1 || m_nCurrentRecord < 0 )
	{
		return;
	}

	// get request
	CString szURL;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

	// check for external
	if( currentRequest.m_external_id > 0 && !appConfig.m_External.szUserSite.IsEmpty() )
	{
		// get user link
		USER_SET User;
		szURL = appConfig.m_External.szUserSite;
		if( appConfig.m_SQL.GetExternalUserID( &User, displayRequest.m_users_email ))
		{
			CString szTemp;
			szTemp.Format( _T("%ld"), User.m_id );
			szURL.Replace( _T("(USERID)"), szTemp );
			szURL.Replace( _T("(USERPID)"), User.m_pwd );
		}
	}
	else
	{
		// get user link
		szURL = appConfig.m_General.szUserSite;
	}

	// format user link
	appConfig.FormatMacros( &szURL, currentRequest.m_id, m_nStaffID );

	// open web browser
	ShellExecute( NULL, _T("open"), szURL, NULL, NULL, SW_SHOWNORMAL );
}

void CCelsusView::OnRequestAdd()
{
	PauseTimer();

	CDlgAddRequest dlgAddRequest;

	dlgAddRequest.m_pszaStatus = &m_szaStatus;
	dlgAddRequest.m_pszaPriority = &m_szaPriority;
	dlgAddRequest.m_pszaMethod = &m_szaMethod;
	dlgAddRequest.m_pszaLibrary = &m_szaLibrary;
	dlgAddRequest.m_pszaCollection = &m_szaCollection;
	dlgAddRequest.m_pszaReferrals = &m_szaReferrals;
	dlgAddRequest.m_pszaCopyright = &m_szaCopyright;
	dlgAddRequest.m_pszaILL = &m_szaILL;
	dlgAddRequest.m_nStaffID = m_nStaffID;
	dlgAddRequest.m_nCurrentLibrary = m_nCurrentLibrary;
	dlgAddRequest.m_bShowThumbnail = m_bShowThumbnail;
	dlgAddRequest.m_bEnableThumbnail = m_bEnableThumbnail;

	// show dialog
	if( dlgAddRequest.DoModal() == IDOK )
		RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestCheckonline()
{
	PauseTimer();

	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	BOOL bRefresh = FALSE;
	BOOL bOpenCheck = TRUE;
	CString szUID;

	// loop through count
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	while( pos )
	{
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );

		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// check for UID
		szUID = appConfig.GetIDFromRequest( currentRequest.m_request );
		
		// check if found
		if( szUID.IsEmpty() )
		{
			// deafult do not open dialog
			bOpenCheck = FALSE;
			// open web browser
			INT nRetVal = AfxMessageBox( IDS_REQUEST_NO_UID, MB_YESNOCANCEL );
			// check respone
			if( nRetVal == IDYES )
			{
				ShellExecute( NULL, _T("open"), appConfig.m_General.szLookupLink, NULL, NULL, SW_SHOWNORMAL );
			}
			if( nRetVal == IDNO )
			{
				// open dialog
				bOpenCheck = TRUE;
			}
		}
		else
		{
			// found UID, check online
			bOpenCheck = TRUE;
		}

		// open check online dialog
		if( bOpenCheck )
		{
			CDlgCheckOnline dlgCheckOnline;
			// set variables
			dlgCheckOnline.m_nStaffID = m_nStaffID;
			dlgCheckOnline.m_nCurrentLibrary = m_nCurrentLibrary;
			dlgCheckOnline.m_pszaLibrary = &m_szaLibrary;
			dlgCheckOnline.m_szUID = szUID;
			dlgCheckOnline.m_nItemID = currentRequest.m_id;			
			dlgCheckOnline.m_szRequest = currentRequest.m_request;
			// show check online dialog
			if( dlgCheckOnline.DoModal() == IDOK )
			{
				// check for link
				if( !appConfig.m_Options.bDisableSourceLinkCheck && !dlgCheckOnline.m_szUID.IsEmpty() )
				{
					// get links
					CArray<REQUEST_LINK> Links;
					appConfig.m_SQL.GetRequestLinks( &Links, dlgCheckOnline.m_szUID );
					// Get Count
					if( Links.GetCount() > 0 )
					{
						// update request
						REQUEST_SET Request;
						appConfig.m_SQL.GetRequestSet( &Request, currentRequest.m_id );
						Request.m_webcheck |= ID_CHECKED_ONLINE_LINK;
						// set request
						appConfig.m_SQL.SetRequestSet( &Request );

						CString szMessage;
						szMessage.Format( _T("Link found for Identifier: %s\n\nDo you want to send link now?"), dlgCheckOnline.m_szUID );
						// show message
						if( AfxMessageBox( szMessage, MB_YESNO ) == IDYES )
						{
							// show send link dialog
							CDlgSendLink dlgSendLink;
							// set variables
							dlgSendLink.m_nStaffID = m_nStaffID;
							dlgSendLink.m_nItemID = currentRequest.m_id;
							// using array for future development
							dlgSendLink.m_szURL = Links.GetAt( 0 ).m_link;
							// show dialog
							if( dlgSendLink.DoModal() == IDOK )
							{
								bRefresh = TRUE;
							}
						}
					}
				}
				// refresh
				bRefresh = TRUE;
			}
		}
	}
	// refresh
	if( bRefresh )
		RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestResendemail()
{
	PauseTimer();

	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	BOOL bSent = TRUE;
	CString szTo;
	CString szFrom;
	CString szName;
	CString szSubject;
	CString szMessage;

	// show wait cursor
	CWaitCursor wait;

	// loop through count
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	while( pos )
	{
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );

		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// get library info
		LIBRARY_LOOKUP Library;
		appConfig.m_SQL.GetDescriptionLibrary( &Library, currentRequest.m_library_id );
		// get variables
		szFrom = Library.szEmail;
		szName = Library.szName;
		szSubject = Library.szSubject;
		// write history
		appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Email resent") );

		// get message
		szMessage = appConfig.ReadFile( appConfig.m_Email.szRemindMessageFile );
		// format message
		appConfig.FormatMacros( &szMessage, currentRequest.m_id );

		CSendMessage send;
		USER_SET User;
		appConfig.m_SQL.GetUserSet( &User, currentRequest.m_user_id );
		if( !send.SendEmail( szName, szFrom, User.m_email, szSubject, szMessage ))
		{
			bSent = FALSE;
			AfxMessageBox( _T("ERROR: Resending email to user.") );
		}
	}
	// sent show dialog
	if( bSent )
		AfxMessageBox( _T("All selected request notifications have been emailed to user.") );

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestNotes()
{
	// kill timer
	PauseTimer();

	// edit notes
	CDlgEditNotes dlgNotes;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

	dlgNotes.m_nItemID = currentRequest.m_id;
	if( dlgNotes.DoModal() == IDOK )
	{
		// write history
		appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Notes Edited") );
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestSource()
{
	// kill timer
	PauseTimer();

	// edit notes
	CDlgEditText dlgText;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

	dlgText.m_szTitle = _T("Edit Request Source");
	dlgText.m_szLabel = _T("Source:");
	dlgText.m_szText = currentRequest.m_source;

	// show dialog
	if( dlgText.DoModal() == IDOK )
	{
		// loop through count
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		while( pos )
		{			
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// remove selection
			//m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
			// set new posistion
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
			// set source
			currentRequest.m_source = dlgText.m_szText;
			currentRequest.m_touched = TRUE;
			// set request
			appConfig.m_SQL.SetRequestSet( &currentRequest );
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Source Edited") );
		}
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestEdit()
{
	// kill timer
	PauseTimer();

	CDlgEditRequest dlgEditRequest;
	// set varialbes
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;

	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

	dlgEditRequest.m_nStaffID = m_nStaffID;
	dlgEditRequest.m_nItemID = currentRequest.m_id;
	if( currentRequest.m_status_id >= STATUS_OFFSET_NA )
		dlgEditRequest.m_bComplete = TRUE;
	dlgEditRequest.m_szaStatus.Copy( m_szaStatus );
	dlgEditRequest.m_szaPriority.Copy( m_szaPriority );
	dlgEditRequest.m_szaMethod.Copy( m_szaMethod );
	dlgEditRequest.m_szaLibrary.Copy( m_szaLibrary );
	dlgEditRequest.m_szaCollection.Copy( m_szaCollection );
	dlgEditRequest.m_szaReferrals.Copy( m_szaReferrals );
	dlgEditRequest.m_szaCopyright.Copy( m_szaCopyright );
	dlgEditRequest.m_szaILL.Copy( m_szaILL );

	// show dialog
	if( dlgEditRequest.DoModal() == IDOK )
	{
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestSendtolibrary()
{
	// kill timer
	PauseTimer();

	// get current
	REQUEST_DISPLAY_SET displayRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );

	CDlgChangeLibrary dlgChange;
	// set variables
	dlgChange.m_nType = CDlgChangeLibrary::TYPE_SENDTO;
	dlgChange.m_nStaffID = m_StaffInfo.nStaffID;
	dlgChange.m_nCurrentLibrary = displayRequest.m_library_id;

	// show dialog
	if( dlgChange.DoModal() == IDOK )
	{
		// loop through count
		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		while( pos )
		{			
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// remove selection
			m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
			// set new posistion
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

			// write history
			CString szHistory;
			szHistory.Format( _T("Sent to library: %s from %s"), m_aLibrary.GetAt( dlgChange.m_nCurrentLibrary ).szDescription, m_aLibrary.GetAt( currentRequest.m_library_id ).szDescription );
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, szHistory );

			// set owner
			currentRequest.m_retain = 0;
			// set redirection
			currentRequest.m_redirected++;
			// set library
			currentRequest.m_library_id = dlgChange.m_nCurrentLibrary;
			// set in library				
			currentRequest.m_atlibrary = dlgChange.m_bIndicator;

			// set status
			if( !dlgChange.m_bRetainStatus )
			{
				currentRequest.m_staff_id = 0;
				currentRequest.m_status_id = STATUS_ID_NEW;
				currentRequest.m_touched = FALSE;
			}

			// set request
			appConfig.m_SQL.SetRequestSet( &currentRequest );
		}
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestSendtoprocessing()
{
	INT nSendLibrary = 0;
	BOOL bRedirected = FALSE;

	if( m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS )
	{
		// set library
		nSendLibrary = m_nCurrentLibrary;
		// show pick library if in triage
		if( nSendLibrary == ID_TRG )
		{
			AfxMessageBox( IDS_SELECT_PROCESS_LIBRARY );

			// get current
			REQUEST_DISPLAY_SET displayRequest;
			m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );

			// show send to library dialog
			CDlgChangeLibrary dlgChange;
			// set variables
			dlgChange.m_nType = CDlgChangeLibrary::TYPE_SENDTO;
			dlgChange.m_nStaffID = m_StaffInfo.nStaffID;
			dlgChange.m_nCurrentLibrary = displayRequest.m_library_id;
			// show dialog
			if( dlgChange.DoModal() == IDOK )
			{
				// set library
				nSendLibrary = dlgChange.m_nCurrentLibrary;
				// set in library
				bRedirected = dlgChange.m_bIndicator;
			}
			else
			{
				return;
			}
		}
		else
		{
			// verify send to processing
			if( AfxMessageBox( IDS_VERIFY_SEND_TO_PROCESSING, MB_YESNO ) == IDNO )
			{
				return;
			}
		}
	}

	// kill timer
	PauseTimer();

	// loop through count
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	while( pos )
	{			
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// remove selection
		m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
		// set owner
		currentRequest.m_staff_id = m_nStaffID;

		// processing
		if( m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS )
		{
			// set touched
			currentRequest.m_touched = TRUE;
			// check for triage
			if( currentRequest.m_library_id == ID_TRG )
			{
				currentRequest.m_library_id = nSendLibrary;
				currentRequest.m_redirected = bRedirected;
			}
			// set status
			currentRequest.m_status_id = STATUS_ID_IN_PROCESS;
			currentRequest.m_retain = 0;
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Sent to processing") );
			// set request
			appConfig.m_SQL.SetRequestSet( &currentRequest );
		}
		else
		{
			// warn
			if( AfxMessageBox( _T("This will claim this request from processing and return it to \"My View\".\n\nDo you want to proceed?"), MB_YESNO ) == IDYES )
			{
				// set touched
				currentRequest.m_touched = TRUE;
				// set status
				currentRequest.m_status_id = STATUS_ID_PENDING;
				// write history
				appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Reclaimed from processing") );
				// set request
				appConfig.m_SQL.SetRequestSet( &currentRequest );
			}
		}
	}
	// refresh
	RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestSplit()
{
	// kill timer
	PauseTimer();

	// fix requests dialog
	CDlgFixRequest dlgFixRequest;
	dlgFixRequest.m_bCombine = FALSE;
	dlgFixRequest.m_nStaffID = m_nStaffID;
	// remove all
	dlgFixRequest.m_aRequestID.RemoveAll();
	// add current
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	dlgFixRequest.m_aRequestID.Add( currentRequest.m_id );

	// show dialog
	if( dlgFixRequest.DoModal() == IDOK )
	{
		// refresh
		RefreshList( TRUE );
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestCombine()
{
	// kill timer
	PauseTimer();

	LONG nUserId = -1;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	// save first
	LONG nIndex = (LONG)pos - 1;

	// save first email address
	m_mRequestSet.Lookup( nIndex, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	nUserId = currentRequest.m_user_id;

	// fix requests dialog
	CDlgFixRequest dlgFixRequest;
	dlgFixRequest.m_bCombine = TRUE;
	dlgFixRequest.m_nStaffID = m_nStaffID;
	// remove all
	dlgFixRequest.m_aRequestID.RemoveAll();

	// loop through count
	while( pos )
	{			
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// remove selection
		m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
		// set request
		dlgFixRequest.m_aRequestID.Add( currentRequest.m_id );
		// check for same user
		if( nUserId != currentRequest.m_user_id )
		{
			CString szMessage;
			LONG nCurrentUserId = currentRequest.m_user_id;
			m_mRequestSet.Lookup( nIndex, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
			USER_SET User;
			appConfig.m_SQL.GetUserSet( &User, currentRequest.m_user_id );
			szMessage.Format( _T("WARNING: User ID for requests do not match (%ld : %ld).\n\nIf you continue all requests will be combined under first selection (User = %s).\n\nDo you wish to continue?"), currentRequest.m_user_id, nCurrentUserId, User.m_email );
			if( AfxMessageBox( szMessage, MB_YESNO | MB_ICONINFORMATION ) == IDNO )
			{
				// start timer
				PauseTimer( FALSE );
				return;
			}
		}
	}

	// show dialog
	if( dlgFixRequest.DoModal() == IDOK )
	{
		// set selection
		if( nIndex > -1 )
		{
			m_ctrlRequestList.SetSelectionMark( nIndex );
			m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
		}
		// refresh
		RefreshList( TRUE );
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestOpen()
{
	// kill timer
	PauseTimer();

	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	// save first
	LONG nIndex = (LONG)pos - 1;

	// loop through count
	while( pos )
	{			
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// get touched
		if( currentRequest.m_touched == FALSE )
		{
			// set touched
			currentRequest.m_touched = TRUE;
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Marked as Opened") );
		}
		else
		{
			// set touched
			currentRequest.m_touched = FALSE;
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Marked as Not Opened") );
		}
		// set request
		appConfig.m_SQL.SetRequestSet( &currentRequest );
	}
	// set selection
	if( nIndex > -1 )
	{
		m_ctrlRequestList.SetSelectionMark( nIndex );
		m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
	}
	// refresh
	RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestClaim()
{
	// kill timer
	PauseTimer();

	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	// save first
	LONG nIndex = (LONG)pos - 1;

	// loop through count
	while( pos )
	{			
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// remove selection
		m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// get owner
		if( currentRequest.m_staff_id == m_nStaffID )
		{
			if( AfxMessageBox( _T("This will release this request and set it as a new request.\n\nDo you want to proceed?"), MB_YESNO ) == IDYES )
			{
				// set status
				currentRequest.m_status_id = STATUS_ID_NEW;
				// reset owner
				currentRequest.m_staff_id = 0;
				// set touched
				currentRequest.m_touched = 0;
				// set retain
				currentRequest.m_retain = 0;
				// write history
				appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Released") );
				// set request
				appConfig.m_SQL.SetRequestSet( &currentRequest );
			}
		}
		else if( currentRequest.m_staff_id == 0 )
		{
			// set status
			currentRequest.m_status_id = STATUS_ID_PENDING;
			// set owner
			currentRequest.m_staff_id = m_nStaffID;
			//// set touched
			//currentRequest.m_touched = 1;
			// set claim date in hold
			currentRequest.m_date_hold = COleDateTime::GetCurrentTime();
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Claimed") );
			// set request
			appConfig.m_SQL.SetRequestSet( &currentRequest );
		}
		else
		{
			if( AfxMessageBox( _T("This will claim this request from the current staff member.\n\nDo you want to proceed?"), MB_YESNO ) == IDYES )
			{
				// set status
				currentRequest.m_status_id = STATUS_ID_PENDING;
				// reset owner
				currentRequest.m_staff_id = m_nStaffID;
				// set retain
				currentRequest.m_retain = 0;
				// set claim date in hold
				currentRequest.m_date_hold = COleDateTime::GetCurrentTime();
				// write history
				appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Released and Claimed") );
				// set request
				appConfig.m_SQL.SetRequestSet( &currentRequest );
			}
		}
	}
	// set selection
	if( nIndex > -1 )
	{
		m_ctrlRequestList.SetSelectionMark( nIndex );
		m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
	}
	// refresh
	RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestRelease()
{
	// kill timer
	PauseTimer();

	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	// save first
	LONG nIndex = (LONG)pos - 1;

	// loop through count
	while( pos )
	{			
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// remove selection
		m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// set status
		currentRequest.m_status_id = STATUS_ID_NEW;
		// reset owner
		currentRequest.m_staff_id = NULL;
		// set touched
		currentRequest.m_touched = NULL;
		currentRequest.m_retain = 0;
		// set request
		appConfig.m_SQL.SetRequestSet( &currentRequest );
		// write history
		appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Released") );
	}
	// set selection
	if( nIndex > -1 )
	{
		m_ctrlRequestList.SetSelectionMark( nIndex );
		m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
	}
	// refresh
	RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestPrintselected()
{
	// kill the timer
	PauseTimer();

	LONG nIndex = -1;
	INT nSendLibrary = 0;
	BOOL bRedirected = 0;

	// set library
	nSendLibrary = m_nCurrentLibrary;

	// redirect to file print
	if( appConfig.m_Options.bDisableTriageProcess )
	{
		if( nSendLibrary == ID_TRG )
		{
			OnFilePrintselected();
			return;
		}
	}

	// print only
	INT_PTR nRetVal = 0;
	CDlgPrintProcess dlgProcess;
	dlgProcess.m_nCount = m_ctrlRequestList.GetSelectedCount();
	dlgProcess.m_nLibraryID = nSendLibrary;

	// do modal dialog
	nRetVal = dlgProcess.DoModal();
	// check return value
	if( nRetVal == IDOK )
	{
		nSendLibrary = dlgProcess.m_nLibraryID;
	}
	else if( nRetVal == IDNO )
	{
		OnFilePrintselected();
		return;
	}
	else
	{
		return;
	}

	// show pick library if in triage
	if( nSendLibrary == ID_TRG )
	{
		AfxMessageBox( IDS_SELECT_PROCESS_LIBRARY );
		
		// get current
		REQUEST_DISPLAY_SET displayRequest;
		m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
		
		// show send to library dialog
		CDlgChangeLibrary dlgChange;
		// set variables
		dlgChange.m_nType = CDlgChangeLibrary::TYPE_SENDTO;
		dlgChange.m_nStaffID = m_StaffInfo.nStaffID;
		dlgChange.m_nCurrentLibrary = displayRequest.m_library_id;
		// show dialog
		if( dlgChange.DoModal() == IDOK )
		{
			// set library
			nSendLibrary = dlgChange.m_nCurrentLibrary;
			// set in library
			bRedirected = dlgChange.m_bIndicator;
		}
		else
		{
			return;
		}
	}

	// check for print template
	if( !appConfig.m_Printing.szRequestTemplate.IsEmpty() && m_bUsePrintTemplate )
	{
		CString szRequestsHTML;
		CString szHTMLRequest;
		INT nCount = 0;

		// read templates
		szHTMLRequest = appConfig.ReadFile( appConfig.m_Printing.szRequestTemplate );

		// loop through count
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		// save first
		nIndex = (LONG)pos - 1;

		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;

		while( pos )
		{
			CString szHTML = szHTMLRequest;
			// get item
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// get request
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
			// format macros
			appConfig.FormatMacros( &szHTML, currentRequest.m_id );
			// add to request
			szRequestsHTML += szHTML;

			// check for page break
			nCount++;
			if( nCount > appConfig.m_Printing.nRequestsPerPage )
			{
				szRequestsHTML += appConfig.m_Printing.szTemplatePageBreak;
				nCount = 0;
			}

			// set touched
			currentRequest.m_touched = TRUE;
			// check for triage
			if( currentRequest.m_library_id != nSendLibrary )
			{
				currentRequest.m_redirected = bRedirected;
				currentRequest.m_library_id = nSendLibrary;
			}
			// set status
			currentRequest.m_status_id = STATUS_ID_IN_PROCESS;
			currentRequest.m_retain = 0;
			// set worker				
			currentRequest.m_staff_id = m_nStaffID;
			// set request
			appConfig.m_SQL.SetRequestSet( &currentRequest );
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Printed sent to Processing") );
		}
		// print requests
		CDlgPreviewHTML dlgPreview;
		dlgPreview.m_bPrint = TRUE;
		dlgPreview.m_bPromptPrinter = TRUE;
		dlgPreview.m_bPrintPreview = appConfig.m_Printing.bPrintPreview;
		dlgPreview.m_szHTML = szRequestsHTML;
		// show message
		dlgPreview.DoModal();
	}
	else
	{
		CDC dc;
		DOCINFO di;
		CPrintInfo Info;
		INT nCount = 0;
		INT nPage = 1;
		INT nTotal = 3;
		BOOL bPrinted = FALSE;
		CPrintDialog printDlg(FALSE);

		// get printer
		if( printDlg.DoModal() == IDCANCEL )
			 return;

		// get CDC	
		HDC hdc = printDlg.CreatePrinterDC();
		if( !dc.Attach( hdc ))
		{
			AfxMessageBox(_T("No printer found!"));
			// start the timer
			PauseTimer( FALSE );
			return;
		}

		// loop through count
		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		// save first
		nIndex = (LONG)pos - 1;
		// loop through
		if( pos )
		{
			// set printed
			bPrinted = TRUE;
			// set printing
			dc.m_bPrinting = TRUE;		
			// Initialise
			::ZeroMemory (&di, sizeof (DOCINFO));
			di.cbSize = sizeof (DOCINFO);
			di.lpszDocName = _T("Celsus");
			// Begin a new print job
			dc.StartDoc(&di);
			// Get the printing extents and store in the m_rectDraw field of a CPrintInfo object		
			INT maxw = dc.GetDeviceCaps(HORZRES);
			INT maxh = dc.GetDeviceCaps(VERTRES);
			Info.m_rectDraw.SetRect(0, 0, maxw, maxh);
			// check for receipt printer
			if( maxw < 2000 || m_bPrintFullCitation)
				nTotal = 1;
		}

		while( pos )
		{
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// remove selection
			m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
			// set new posistion			
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

			// start page
			if( nCount < 1 )
			{
				dc.StartPage();    // begin new page
				Info.m_nCurPage = nPage;
			}
			// print request
			if( appConfig.PrintRequest( &dc, currentRequest.m_id, nCount ))
			{
				// set touched
				currentRequest.m_touched = TRUE;
				// check for triage
				if( currentRequest.m_library_id != nSendLibrary )
				{
					currentRequest.m_redirected = bRedirected;
					currentRequest.m_library_id = nSendLibrary;
				}
				// set status
				currentRequest.m_status_id = STATUS_ID_IN_PROCESS;
				// set worker				
				currentRequest.m_staff_id = m_nStaffID;
				// set request
				appConfig.m_SQL.SetRequestSet( &currentRequest );
				// increment count
				nCount++;		
				// write history
				appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Printed sent to Processing") );
			}
			if( nCount >= nTotal )
			{
				// restart count
				nCount = 0;
				// increment page
				nPage++;
				// clean up
				dc.EndPage();   // end page
			}
		}
		// end a print job
		if( bPrinted )
			dc.EndDoc();
	}

	// set selection
	if( nIndex > -1 )
	{
		m_ctrlRequestList.SetSelectionMark( nIndex );
		m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
	}
	// refresh
	RefreshList( TRUE );
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestSendlink()
{
	// pause timer
	PauseTimer();

	// loop through count
	BOOL bRefresh = FALSE;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	// save first
	LONG nIndex = (LONG)pos - 1;
	// loop
	while( pos )
	{
		// get item
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
		// show send link dialog
		CDlgSendLink dlgSendLink;
		// set variables
		dlgSendLink.m_nStaffID = m_nStaffID;
		dlgSendLink.m_nItemID = currentRequest.m_id;
		// show dialog
		if( dlgSendLink.DoModal() == IDOK )
		{
			bRefresh = TRUE;
		}
	}
	// refresh
	if( bRefresh )
	{
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		// loop
		while( pos )
		{
			// get item
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// remove selection
			m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		}
		// set selection
		if( nIndex > -1 )
		{
			m_ctrlRequestList.SetSelectionMark( nIndex );
			m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
		}
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestProcess()
{
	// check for process as complete
	if( m_bProcessComplete )
	{
		// do manual complete
		OnRequestManualcomplete();
		return;
	}

	// pause timer
	PauseTimer();

	// loop through count
	BOOL bRefresh = FALSE;
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	// save first
	LONG nIndex = (LONG)pos - 1;
	// loop
	while( pos )
	{
		// get item
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// check send type
		if( m_aMethod.GetAt( currentRequest.m_method_id ).nElectronic == 0 )
		{
			CDlgComplete dlgComplete;
			// set variables
			dlgComplete.m_nItemID = currentRequest.m_id;
			dlgComplete.m_nStaffID = m_nStaffID;
			dlgComplete.m_nLibraryID = m_nCurrentLibrary;
			dlgComplete.m_pszaCollection = &m_szaCollection;
			// show dialog
			if( dlgComplete.DoModal() == IDOK )
			{
				bRefresh = TRUE;
				// write history
				appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Sent to user") );
			}
		}
		else
		{
			if( appConfig.m_General.bSendFilesViaHTTP )
			{
				CDlgSendFileHtml dlgSend;
				// set variables
				dlgSend.m_nItemID = currentRequest.m_id;
				dlgSend.m_nStaffID = m_nStaffID;
				dlgSend.m_nLibraryID = m_nCurrentLibrary;
				// show dialog
				if( dlgSend.DoModal() == IDOK )
				{
					bRefresh = TRUE;
					// write history
					appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent to web server via HTTP") );
				}
			}
			else
			{
				CDlgSendRequest dlgSend;
				// set variables
				dlgSend.m_nItemID = currentRequest.m_id;
				dlgSend.m_nStaffID = m_nStaffID;
				dlgSend.m_nLibraryID = m_nCurrentLibrary;
				dlgSend.m_bShowThumbnail = m_bShowThumbnail;
				dlgSend.m_bEnableThumbnail = m_bEnableThumbnail;

				dlgSend.m_pszaStatus = &m_szaStatus;
				dlgSend.m_pszaPriority = &m_szaPriority;
				dlgSend.m_pszaMethod = &m_szaMethod;
				dlgSend.m_pszaLibrary = &m_szaLibrary;
				dlgSend.m_pszaCollection = &m_szaCollection;
				dlgSend.m_pszaReferrals = &m_szaReferrals;
				dlgSend.m_pszaCopyright = &m_szaCopyright;
				dlgSend.m_pszaILL = &m_szaILL;

				// show dialog
				if( dlgSend.DoModal() == IDOK )
				{
					bRefresh = TRUE;
					// write history
					if( dlgSend.m_nSendType == 0 )
						appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent to web server") );
					else if( dlgSend.m_nSendType == 1 )
						appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent as attachment") );
					else
						appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgSend.m_nStatus, _T("Sent to user") );
				}
			}
		}
	}
	// refresh
	if( bRefresh )
	{
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		// loop
		while( pos )
		{
			// get item
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// remove selection
			m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		}
		// set selection
		if( nIndex > -1 )
		{
			m_ctrlRequestList.SetSelectionMark( nIndex );
			m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
		}
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestMarkasheld()
{
	// kill timer
	PauseTimer();

	CDlgHoldRequest dlgHoldRequest;
	// set varialbes
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	
	dlgHoldRequest.m_nItemID = currentRequest.m_id;
	dlgHoldRequest.m_pszaLibrary = &m_szaLibrary;

	// show dialog
	if( dlgHoldRequest.DoModal() == IDOK )
	{
		// write history
		appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, _T("Marked as Held") );
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestManualcomplete()
{
	// kill timer
	PauseTimer();

	BOOL bRefresh = FALSE;
	LONG nIndex = -1;

	CDlgCompleteManual dlgCompleteManual;
	// set varialbes
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	dlgCompleteManual.m_nStaffID = m_nStaffID;
	dlgCompleteManual.m_nLibraryID = m_nCurrentLibrary;
	dlgCompleteManual.m_nItemID = currentRequest.m_id;
	dlgCompleteManual.m_pszaMethod = &m_szaMethod;
	dlgCompleteManual.m_pszaCollection = &m_szaCollection;
	dlgCompleteManual.m_bProcessComplete = m_bProcessComplete;

	// set exit on return
	if( m_bProcessComplete )
		dlgCompleteManual.m_bExitOnReturn = TRUE;

	// show dialog
	if( dlgCompleteManual.DoModal() == IDOK )
	{
		CWaitCursor wait;
		// refresh
		bRefresh = TRUE;
		// loop through count
		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		// save first
		nIndex = (LONG)pos - 1;
		// loop
		while( pos )
		{
			// get item
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// remove selection
			m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
			// set new posistion
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
			// set status
			currentRequest.m_staff_id = m_nStaffID;
			currentRequest.m_status_id = STATUS_ID_COMPLETE;
			currentRequest.m_method_id = dlgCompleteManual.m_nMethodID;
			currentRequest.m_collection_id = dlgCompleteManual.m_nCollectionID;
			currentRequest.m_notes = dlgCompleteManual.m_szNotes;
			currentRequest.m_date_out = COleDateTime::GetCurrentTime();
			currentRequest.m_touched = TRUE;
			currentRequest.m_material = dlgCompleteManual.m_bElectronic;
			currentRequest.m_fee_service = dlgCompleteManual.m_dServiceFee;
			currentRequest.m_fee_copyright = dlgCompleteManual.m_dCopyrightFee;
			currentRequest.m_fee_misc = dlgCompleteManual.m_dMiscFee;
			currentRequest.m_canceled = dlgCompleteManual.m_bCanceled;
			currentRequest.m_retain = 0;
			// set request
			appConfig.m_SQL.SetRequestSet( &currentRequest );
			// write history
			CString szHistory;
			szHistory = _T("Manually Completed");
			if( currentRequest.m_canceled )
				szHistory += _T(" - Canceled");
			if( dlgCompleteManual.m_bDuplicate )
				szHistory += _T(" - Duplicate");
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, currentRequest.m_status_id, szHistory );
		}
	}

	// refresh
	if( bRefresh )
	{
		// set selection
		if( nIndex > -1 )
		{
			m_ctrlRequestList.SetSelectionMark( nIndex );
			m_ctrlRequestList.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
		}
		// refresh
		RefreshList( TRUE );
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestNotavailable()
{
	// kill timer
	PauseTimer();

	CDlgRequestNA dlgRequestNA;
	// set varialbes
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	dlgRequestNA.m_nItemID = currentRequest.m_id;
	dlgRequestNA.m_nStaffID = m_nStaffID;

	// show dialog
	if( dlgRequestNA.DoModal() == IDOK )
	{
		// write history
		appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, dlgRequestNA.m_nStatus, dlgRequestNA.m_szReason );
		// refresh
		RefreshList( TRUE );
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestHistory()
{
	// kill timer
	PauseTimer();

	CDlgHistoryList HistoryDlg;
	// set varialbes
	REQUEST_SET currentRequest;
	REQUEST_DISPLAY_SET displayRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, displayRequest );
	appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
	HistoryDlg.m_nID = currentRequest.m_id;
	HistoryDlg.m_nStaffID = m_nStaffID;
	HistoryDlg.m_pszaStatus = &m_szaStatus;
	HistoryDlg.m_paStaffInfo = &m_aStaffInfo;
	// show dialog
	if( HistoryDlg.DoModal() == IDOK )
	{
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnRequestResubmit()
{
	// kill timer
	PauseTimer();

	// loop through count
	REQUEST_SET currentRequest;
	REQUEST_SET newRequest;
	REQUEST_DISPLAY_SET displayRequest;
	POSITION pos = NULL;
	pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
	while( pos )
	{			
		LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
		// remove selection
		m_ctrlRequestList.SetItemState( nItem, NULL, LVIS_SELECTED | LVIS_FOCUSED );
		// set new posistion
		m_mRequestSet.Lookup( nItem, displayRequest );
		appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );

		// get empty request
		appConfig.m_SQL.GetEmptyRequest( &newRequest );

		// set variables
		newRequest.m_staff_id = 0;
		newRequest.m_user_id = currentRequest.m_user_id;
		newRequest.m_date_in = COleDateTime::GetCurrentTime();
		//newRequest.m_date_hold = NULL;
		//newRequest.m_date_out = NULL;
		newRequest.m_status_id = STATUS_ID_NEW;
		newRequest.m_collection_id = currentRequest.m_collection_id;
		newRequest.m_library_id = currentRequest.m_library_id;
		newRequest.m_atlibrary = currentRequest.m_atlibrary;
		newRequest.m_step_id = currentRequest.m_step_id;
		newRequest.m_request = currentRequest.m_request;
		newRequest.m_instructions = currentRequest.m_instructions;
		newRequest.m_information = currentRequest.m_information;
		newRequest.m_notes = currentRequest.m_notes;
		newRequest.m_uid = currentRequest.m_uid;
		newRequest.m_title = currentRequest.m_title;
		newRequest.m_source = currentRequest.m_source;
		newRequest.m_priority_id = currentRequest.m_priority_id;
		newRequest.m_method_id = currentRequest.m_method_id;
		newRequest.m_ill_id = currentRequest.m_ill_id;
		newRequest.m_file = _T("");
		newRequest.m_viewed = 0;
		newRequest.m_redirected = 0;
		newRequest.m_touched = 0;
		newRequest.m_webcheck = 0;
		newRequest.m_deleted = 0;
		newRequest.m_invoiced = 0;
		newRequest.m_type = currentRequest.m_type;
		newRequest.m_level = currentRequest.m_level;
		newRequest.m_project = currentRequest.m_project;
		newRequest.m_taxable = currentRequest.m_taxable;
		newRequest.m_overdue = currentRequest.m_overdue;
		newRequest.m_copyright = currentRequest.m_copyright;
		newRequest.m_canceled = 0;
		newRequest.m_resubmitted = currentRequest.m_resubmitted + 1;
		newRequest.m_finalized = 0;
		newRequest.m_referrals = currentRequest.m_referrals;
		newRequest.m_manual = currentRequest.m_manual;
		newRequest.m_material = currentRequest.m_material;
		newRequest.m_fee_copyright = currentRequest.m_fee_copyright;
		newRequest.m_fee_service = currentRequest.m_fee_service;
		newRequest.m_fee_misc = currentRequest.m_fee_misc;
		newRequest.m_retain = 0;

		// add request
		if( appConfig.m_SQL.SetRequestSet( &newRequest, -1, TRUE ) )
		{
			// write history
			appConfig.UpdateRequestHistory( currentRequest.m_id, m_nStaffID, newRequest.m_status_id, _T("Resubmitted") );
			// show message
			AfxMessageBox( IDS_REQUEST_RESUBMITTED );
		}
	}
}

void CCelsusView::OnRecordExporttoexcel()
{
	// Show open file dialog
	// szFilters is a text string that includes two file name filters:   
	TCHAR szFilters[]=_T("Excel CSV Files (*.CSV)|*.CSV|Text Files (*.TXT)|*.TXT|Excel DIF Files (*.DIF)|*.DIF|All Files (*.*)|*.*||");
	// Create an Open dialog; the default file name extension is ".EXE".
	CFileDialog fileDlg (FALSE, _T("DIF"), _T("Celsus Export"), OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR, szFilters, this);
	if( fileDlg.DoModal() == IDOK )
	{
		CString szTemp;
		CString szDelimiter = _T("\t");
		CString szFile = fileDlg.GetPathName();

		// delete file
		if( PathFileExists( szFile ))
		{
			if( DeleteFile( szFile ) == 0 )
			{
				AfxMessageBox( IDS_ERROR_DELETE_FILES, MB_OK | MB_ICONSTOP );
				return;
			}
		}

		// show wait 
		CWaitCursor wait;

		// set delimiter
		if( szFile.Right( 3 ).CompareNoCase( _T("DIF")) == 0 )
			szDelimiter = _T("\t");
		if( szFile.Right( 3 ).CompareNoCase( _T("TXT")) == 0 )
			szDelimiter = _T("\t");
		if( szFile.Right( 3 ).CompareNoCase( _T("CSV")) == 0 )
			szDelimiter = _T(",");

		// write header
		szTemp.Format(_T("\"ID\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Date\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Name\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Email\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Location\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Phone\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Fax\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Instructions\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Method\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Priority\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"ILL\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Library\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Request\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Redirected\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Deleted\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Opened\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Notes\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		szTemp.Format(_T("\"Status\"%s"), szDelimiter);
		appConfig.WriteToFile( szFile, szTemp );

		// last one no delimiter
		szTemp.Format(_T("\"Staff\"%s"), _T(""));
		appConfig.WriteToFile( szFile, szTemp );

		// write end
		appConfig.WriteToFile( szFile, _T("\n") );

		// loop through count
		LONG nCount = 0;
		REQUEST_SET currentRequest;
		REQUEST_DISPLAY_SET displayRequest;
		USER_SET User;
		POSITION pos = NULL;
		pos = m_ctrlRequestList.GetFirstSelectedItemPosition();
		while( pos )
		{
			// count it
			nCount++;
			// get item
			LONG nItem = m_ctrlRequestList.GetNextSelectedItem( pos );
			// set new posistion
			m_mRequestSet.Lookup( nItem, displayRequest );
			appConfig.m_SQL.GetRequestSet( &currentRequest, displayRequest.m_id );
			appConfig.m_SQL.GetUserSet( &User, currentRequest.m_user_id );

			// build export string
			szTemp.Format( _T("\"%.8ld\"%s"), currentRequest.m_id, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp );

			szTemp.Format( _T("\"%s\"%s"), currentRequest.m_date_in.Format( appConfig.m_General.szDateFormat ), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), User.m_name, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), User.m_email, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), appConfig.QuoteString(User.m_company), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), User.m_phone, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), User.m_fax, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), appConfig.QuoteString(currentRequest.m_instructions), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), m_szaMethod.GetAt( currentRequest.m_method_id ), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), m_szaPriority.GetAt( currentRequest.m_priority_id ), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), m_szaILL.GetAt( currentRequest.m_ill_id ), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), m_szaLibrary.GetAt( currentRequest.m_library_id ), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%s\"%s"), appConfig.QuoteString(currentRequest.m_request), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );
			
			szTemp.Format( _T("\"%d\"%s"), currentRequest.m_redirected, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp );

			szTemp.Format( _T("\"%d\"%s"), currentRequest.m_deleted, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp );

			szTemp.Format( _T("\"%d\"%s"), currentRequest.m_touched, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp );
			
			szTemp.Format( _T("\"%s\"%s"), appConfig.QuoteString(currentRequest.m_notes), szDelimiter );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			szTemp.Format( _T("\"%d\"%s"), currentRequest.m_status_id, szDelimiter );
			appConfig.WriteToFile( szFile, szTemp );

			// lat one no delimter
			szTemp.Format( _T("\"%s\"%s"), m_aStaffInfo.GetAt( currentRequest.m_staff_id ).szStaffName, _T("") );
			appConfig.WriteToFile( szFile, szTemp, TRUE );

			// write end
			appConfig.WriteToFile( szFile, _T("\n") );
		}
		// show export dialog
		szTemp.Format( _T("%ld of %ld records were exported to %s."), nCount, m_ctrlRequestList.GetSelectedCount(), szFile );
		AfxMessageBox( szTemp );
	}
}

void CCelsusView::OnSortInvoiced()
{
	// toggle
	if( m_nSortBy == SORT_NORMAL )
	{
		// set sort type
		m_nSortBy = SORT_INVOICED;
		m_szSort = _T("requests.invoiced");
		m_szSort += _T(" DESC");

		// set tab title
		SetTabTitle( GetTabView(), _T("[Invoiced]") );
	}
	else
	{
		// rest to normal
		m_nSortBy = SORT_NORMAL;
		// set tab title
		SetTabTitle( GetTabView(), NULL, TRUE );
	}

	// refresh
	RefreshList( TRUE );
}

void CCelsusView::OnViewSavecolumnorder()
{
	// save column order
	if( SetColumnOrder() )
	{
		// show message
		AfxMessageBox( _T("Column Order Saved.") );
	}
}

void CCelsusView::OnExternallIllSendFile()
{
	// pause timer
	PauseTimer();

	if( appConfig.m_General.bSendFilesViaHTTP )
	{
		CDlgSendFileHtml dlgSend;
		// set variables
		dlgSend.m_nStaffID = m_nStaffID;
		dlgSend.m_nLibraryID = m_nCurrentLibrary;
		// show dialog
		if( dlgSend.DoModal() == IDOK )
		{
		}
	}
	else
	{
		CDlgSendRequest dlgSend;
		// set variables
		dlgSend.m_nSendType = SEND_FTP;
		dlgSend.m_nStaffID = m_nStaffID;
		dlgSend.m_nLibraryID = m_nCurrentLibrary;
		dlgSend.m_bShowThumbnail = m_bShowThumbnail;
		dlgSend.m_bEnableThumbnail = m_bEnableThumbnail;

		dlgSend.m_pszaStatus = &m_szaStatus;
		dlgSend.m_pszaPriority = &m_szaPriority;
		dlgSend.m_pszaMethod = &m_szaMethod;
		dlgSend.m_pszaLibrary = &m_szaLibrary;
		dlgSend.m_pszaCollection = &m_szaCollection;
		dlgSend.m_pszaReferrals = &m_szaReferrals;
		dlgSend.m_pszaCopyright = &m_szaCopyright;
		dlgSend.m_pszaILL = &m_szaILL;

		// show dialog
		if( dlgSend.DoModal() == IDOK )
		{
		}
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnUpdateFilePrintselected(CCmdUI *pCmdUI)
{
	// diable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateFileProcessascomplete(CCmdUI *pCmdUI)
{
	// set check
	pCmdUI->SetCheck( m_bProcessComplete );
}

void CCelsusView::OnUpdateEditCopy(CCmdUI *pCmdUI)
{
	// update copy menu
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
		SetClipboardMenu( pCmdUI );
}

void CCelsusView::OnUpdateEditCopyitemid(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateEditUsersCurrent(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateEditStaffCurrent(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_CurrentRequest.m_staff_id > 0 && m_ctrlRequestList.GetSelectedCount() == 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateUsersiteCurrent(CCmdUI *pCmdUI)
{
	// diable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnViewRequestwindow()
{
	// toggle
	m_bShowRequestWindow = !m_bShowRequestWindow;
	// show
	ShowRequestDlg( m_bShowRequestWindow );
}

void CCelsusView::OnViewHistorytoday()
{
	// kill timer
	PauseTimer();

	CDlgHistoryList HistoryDlg;
	// set varialbes
	HistoryDlg.m_nType = HistoryDlg.HISTORY_RECENT;
	HistoryDlg.m_nStaffID = m_nStaffID;
	HistoryDlg.m_pszaStatus = &m_szaStatus;
	HistoryDlg.m_paStaffInfo = &m_aStaffInfo;
	// show dialog
	if( HistoryDlg.DoModal() == IDOK )
	{
	}
	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnViewLinkslist()
{
	// pause timer
	PauseTimer();

	// show link dialog
	CDlgEditLinks dlgLinks;
	dlgLinks.m_nStaffID = m_nStaffID;
	dlgLinks.DoModal();

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnViewSourcelinkslist()
{
	// pause timer
	PauseTimer();

	// show source links dialog
	CDlgListSource dlgSource;
	dlgSource.m_nStaffID = m_nStaffID;
	dlgSource.DoModal();

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnSourceOpensource()
{
	// get request
	REQUEST_DISPLAY_SET currentRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );
	if( !currentRequest.m_source_link.IsEmpty() )
		ShellExecute( m_hWnd, NULL, currentRequest.m_source_link, NULL, NULL, SW_SHOWNORMAL );
}

void CCelsusView::OnSourceEditsource()
{
	// pause timer
	PauseTimer();

	// get request
	REQUEST_DISPLAY_SET currentRequest;
	m_mRequestSet.Lookup( m_nCurrentRecord, currentRequest );

	// get source
	SOURCE_LINK Link;
	if( appConfig.m_SQL.GetSourceLink( &Link, _T("link"), currentRequest.m_source_link ))
	{
		CDlgEditSource dlgSource;
		dlgSource.m_nItemID = Link.m_id;
		dlgSource.m_nStaffID = m_nStaffID;
		// show dialog
		if( dlgSource.DoModal() == IDOK )
		{
			// refresh
			RefreshList( TRUE );
		}
	}

	// start timer
	PauseTimer( FALSE );
}

void CCelsusView::OnUpdateRequestCheckonline(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestResendemail(CCmdUI *pCmdUI)
{
	// set check
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id >= STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestNotes(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestSource(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestEdit(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 ); //&& m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestSendtolibrary(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}


void CCelsusView::OnUpdateRequestSendtoprocessing(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > ID_TRG )
	{
		if( appConfig.m_Options.bDisableTriageProcess && m_CurrentRequest.m_library_id == 0 )
			pCmdUI->Enable( FALSE );
		else
			pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
	// set check
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->SetCheck( m_CurrentRequest.m_status_id == STATUS_ID_IN_PROCESS );
	}
}

void CCelsusView::OnUpdateRequestOpen(CCmdUI *pCmdUI)
{
	// set check
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->SetCheck( m_CurrentRequest.m_touched > 0 && m_ctrlRequestList.GetSelectedCount() >= 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestSplit(CCmdUI *pCmdUI)
{
	// disable if more then one record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 && m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestCombine(CCmdUI *pCmdUI)
{
	// enabe if more then one record is selected and emails match
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() > 1 && m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestClaim(CCmdUI *pCmdUI)
{
	// set check
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
		pCmdUI->SetCheck( m_CurrentRequest.m_staff_id == m_nStaffID );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestRelease(CCmdUI *pCmdUI)
{
	// enable if record is not claimed
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_staff_id > 0 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestPrintselected(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id != STATUS_ID_IN_PROCESS && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestSendlink(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestProcess(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestMarkasheld(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestManualcomplete(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestNotavailable(CCmdUI *pCmdUI)
{
	// enable if record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() >= 1 && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestHistory(CCmdUI *pCmdUI)
{
	// enable if more then one record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateRequestResubmit(CCmdUI *pCmdUI)
{
	// enable if more then one record is selected
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 )
	{
		pCmdUI->Enable( m_ctrlRequestList.GetSelectedCount() == 1 && m_CurrentRequest.m_status_id >= STATUS_OFFSET_NA && m_CurrentRequest.m_external_id <= 0 );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateSortInvoiced(CCmdUI *pCmdUI)
{
	// set check
	if( m_nCurrentRecord >= 0 && m_nRecordCount > 0 && m_nViewMode == TAB_COMPLETE )
	{
		pCmdUI->SetCheck( m_nSortBy == SORT_INVOICED );
	}
	else
	{
		pCmdUI->Enable( FALSE );
	}
}

void CCelsusView::OnUpdateViewRequestwindow(CCmdUI *pCmdUI)
{
	if( !m_pRequestViewDlg )
		m_bShowRequestWindow = FALSE;
	pCmdUI->SetCheck( m_bShowRequestWindow );
}

void CCelsusView::OnUpdateExternalIllEdituser(CCmdUI *pCmdUI)
{
	// enable level greater then editor
	pCmdUI->Enable( appConfig.m_nStaffLevel >= STAFF_EDITOR );
}

CWnd* CCelsusView::GetFocusClass(LPCTSTR WinClass)
{
	CWnd* pWin;
	BOOL Result = FALSE;
	// Does a valid child have the Focus?
	if( (pWin = GetFocus()) != NULL && pWin->m_hWnd != NULL )
	{
		TCHAR Text[64]=_T("");
		// If so, what is it's class (i.e., "EDIT", "LISTBOX", etc.)
		if( GetClassName( pWin->m_hWnd, Text, sizeof(Text) ))
			if( _tcsicmp( Text, WinClass ) == 0 )
				return( pWin ); // If a match, return the CWnd*
	}
	return( NULL );	//No good, return NULL
}

void CCelsusView::SetClipboardMenu(CCmdUI* pCmdUI)
{
	BOOL bResult = FALSE;

	CEdit* pEdit = (CEdit*) GetFocusClass( _T("EDIT") );
	if( pEdit )	// Make sure current control is an edit box
	{
		// If it is an edit, what menu item is being enabled/disabled?
		if( pCmdUI->m_nID == ID_EDIT_PASTE )
		{
			// Paste is enabled only if there is text in the clipboard...
			if( OpenClipboard() )
			{
				if( GetClipboardData( CF_TEXT ) )
					bResult = TRUE;
				CloseClipboard();
			}
		}
		else if( pCmdUI->m_nID==ID_EDIT_CUT || pCmdUI->m_nID==ID_EDIT_COPY )
		{
			// Cut and Copy are enabled only if something is highlighter
			int Start, Stop;
			pEdit->GetSel(Start, Stop);
			if( Start != Stop)
				bResult = TRUE;
		}
	}

	// check for Explorer Window
	CExplorer_window* pBrowser = (CExplorer_window*) GetFocusClass( _T("Internet Explorer_Server") );
	if( pBrowser )
	{
		// request window
		CFindWnd FindIEWndRequest( m_wbRequest.m_hWnd, _T("Internet Explorer_Server"));
		if( FindIEWndRequest.m_hWnd == pBrowser->m_hWnd )
			bResult = m_wbRequest.QueryStatusWB( OLECMDID_COPY ) & OLECMDF_ENABLED;

		// request window
		CFindWnd FindIEWndInformation( m_wbInformation.m_hWnd, _T("Internet Explorer_Server"));
		if( FindIEWndInformation.m_hWnd == pBrowser->m_hWnd )
			bResult = m_wbInformation.QueryStatusWB( OLECMDID_COPY ) & OLECMDF_ENABLED;
	}

	pCmdUI->Enable( bResult );	// Enable or Disable the menu
}

void CCelsusView::DoClipboardOp(INT ID)
{
	CEdit* pEdit = (CEdit*) GetFocusClass( _T("EDIT") );
	if( pEdit )	// Is the current window an Edit box?
	{
		// If so, invoke the CEdit routine for the clipboard operation
		if( ID==ID_EDIT_CUT )
			pEdit->Cut();
		else
		if( ID==ID_EDIT_COPY )
			pEdit->Copy();
		else
		if( ID==ID_EDIT_PASTE )
			pEdit->Paste();
	}
	
	// check for Explorer Window
	CExplorer_window* pBrowser = (CExplorer_window*) GetFocusClass( _T("Internet Explorer_Server") );
	if( pBrowser )
	{
		// If so, invoke the browser routine for the clipboard operation
		if( ID==ID_EDIT_COPY )
		{
			// request window
			CFindWnd FindIEWndRequest( m_wbRequest.m_hWnd, _T("Internet Explorer_Server"));
			if( FindIEWndRequest.m_hWnd == pBrowser->m_hWnd )
				m_wbRequest.ExecWB( OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL );

			// request window
			CFindWnd FindIEWndInformation( m_wbInformation.m_hWnd, _T("Internet Explorer_Server"));
			if( FindIEWndInformation.m_hWnd == pBrowser->m_hWnd )
				m_wbInformation.ExecWB( OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL );
		}
	}
}

void CCelsusView::CmdRouteMenu(CWnd* pWnd,CMenu* pPopupMenu)
{
    CCmdUI state;
    state.m_pMenu = pPopupMenu;
    state.m_pParentMenu = pPopupMenu;
    state.m_nIndexMax = pPopupMenu->GetMenuItemCount();

    for (state.m_nIndex = 0; 
         state.m_nIndex < state.m_nIndexMax; 
         state.m_nIndex++) 
    {
        state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);

        // menu separator or invalid cmd - ignore it
        if (state.m_nID == 0) continue; 

        if (state.m_nID == (UINT)-1)
        {
            // possibly a popup menu, route to child menu if so
            CMenu* pSub=pPopupMenu->GetSubMenu(state.m_nIndex);
            if(pSub) CmdRouteMenu(pWnd,pSub);
        }
        else 
        {
            // normal menu item, Auto disable if command is 
            // _not_ a system command.
            state.m_pSubMenu = NULL;
            state.DoUpdate(pWnd, FALSE);
        }
    }
}

BOOL CCelsusView::GetStaff(void)
{
	// clear array
	m_aStaffInfo.RemoveAll();
	// fetch descriptions
	appConfig.m_SQL.GetDescriptionStaffs( &m_aStaffInfo );

	return TRUE;
}

BOOL CCelsusView::GetUsers(void)
{
	// clear array
	m_aUserInfo.RemoveAll();
	// fetch descriptions
	appConfig.m_SQL.GetDescriptionUsers( &m_aUserInfo );

	return TRUE;
}

BOOL CCelsusView::GetPriorities(void)
{
	PRIORITY_LOOKUP Priority;

	// clear array
	m_szaPriority.RemoveAll();
	m_aPriority.RemoveAll();

	// fetch descriptions
	appConfig.m_SQL.GetDescriptions( CMySQLEx::priority, &m_szaPriority );
	appConfig.m_SQL.GetDescriptionPrioritys( &m_aPriority );

	return TRUE;
}

BOOL CCelsusView::GetLibraries(void)
{
	// clear array
	m_szaLibrary.RemoveAll();
	m_aLibrary.RemoveAll();

	// fetch descriptions
	appConfig.m_SQL.GetDescriptions( CMySQLEx::library, &m_szaLibrary );
	appConfig.m_SQL.GetDescriptionLibrarys( &m_aLibrary );

	return TRUE;
}

BOOL CCelsusView::GetCollections(void)
{
	// clear array
	m_szaCollection.RemoveAll();
	// fetch descriptions
	appConfig.m_SQL.GetDescriptions( CMySQLEx::collection, &m_szaCollection );
	appConfig.m_SQL.GetDescriptionCollections( &m_aCollection );

	return TRUE;
}

BOOL CCelsusView::GetMethods(void)
{
	// clear array
	m_szaMethod.RemoveAll();
	m_aMethod.RemoveAll();

	// fetch descriptions
	appConfig.m_SQL.GetDescriptions( CMySQLEx::method, &m_szaMethod );
	appConfig.m_SQL.GetDescriptionMethods( &m_aMethod );

	return TRUE;
}

BOOL CCelsusView::GetStatuses(void)
{
	// clear array
	m_szaStatus.RemoveAll();
	m_aStatus.RemoveAll();

	// fetch descriptions
	appConfig.m_SQL.GetDescriptions( CMySQLEx::status, &m_szaStatus );
	appConfig.m_SQL.GetDescriptionStatuss( &m_aStatus );

	return TRUE;
}

BOOL CCelsusView::GetDescriptions(void)
{
	// clear descriptions	
	m_szaILL.RemoveAll();
	m_szaUserType.RemoveAll();
	m_szaReferrals.RemoveAll();
	m_szaCopyright.RemoveAll();

	//description_ill
	appConfig.m_SQL.GetDescriptions( CMySQLEx::ill, &m_szaILL );

	//description_user_type
	appConfig.m_SQL.GetDescriptions( CMySQLEx::user_type, &m_szaUserType );

	//description_referrals
	appConfig.m_SQL.GetDescriptions( CMySQLEx::referrals, &m_szaReferrals );

	//description_copyright
	appConfig.m_SQL.GetDescriptions( CMySQLEx::copyright, &m_szaCopyright );

	return TRUE;
}

BOOL CCelsusView::RefreshList(INT nLevel)
{
	CWaitCursor wait;
	LONGLONG nCurrentCount = 0;

	// kill the timer
	PauseTimer();

	// check claim limit
	if( appConfig.m_General.nHoursClaimLimit > 0 )
	{
		LONG nRowsUpdated = 0;
		nRowsUpdated = appConfig.m_SQL.UpdateClaimLimit( appConfig.m_General.nHoursClaimLimit );
		CString szStatus;
		szStatus.Format( _T("Release Claimed Requests... %ld"), nRowsUpdated );
		((CMainFrame*)GetParentFrame())->SetStatus( 0, szStatus );
	}

	// set status
	((CMainFrame*)GetParentFrame())->SetStatus( 0, _T("Querying Database...") );

	// save current
	m_nCurrentRecord = m_ctrlRequestList.GetSelectionMark();
	// get current count
	nCurrentCount = m_nRecordCount;

	// only use hints on complete
	if( m_nViewMode == TAB_COMPLETE )
	{
		// get new record count	
		m_nRecordCount = appConfig.m_SQL.GetRequestCount( m_szFilter );
	}
	else
	{
		// get new record count
		m_nRecordCount = UpdateRequestArray();
	}

	// reset ticker
	m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

	// check list count
	if( nCurrentCount != m_nRecordCount || nLevel == 1 )
	{
		// update count
		m_ctrlRequestList.SetItemCountEx( (INT)m_nRecordCount, LVSICF_NOSCROLL );//| LVSICF_NOINVALIDATEALL );
		//set to a level 1
		nLevel = 1;
	}

	// no records empty list
	if( m_nRecordCount <= 0 )
	{
		// empty array
		m_ctrlRequestList.DeleteAllItems();
		// update request deatil
		UpdateRequestDetail();
	}

	// redraw items
	if( nLevel == 1 )
	{
		// reset cache
		m_bResetCache = TRUE;

		// update window
		INT nTop = m_ctrlRequestList.GetTopIndex();
		INT nLast = nTop + m_ctrlRequestList.GetCountPerPage();
		m_ctrlRequestList.RedrawItems( nTop, nLast );

		// set selection
		if( m_ctrlRequestList.GetSelectionMark() == -1 && m_nRecordCount > 0 )
		{
			m_ctrlRequestList.SetSelectionMark( 0 );
			m_ctrlRequestList.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
			m_ctrlRequestList.EnsureVisible( 0, FALSE );
		}
		else
		{
			m_ctrlRequestList.SetSelectionMark( (LONG)m_nCurrentRecord );
			m_ctrlRequestList.SetItemState( (LONG)m_nCurrentRecord, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
			m_ctrlRequestList.EnsureVisible( (LONG)m_nCurrentRecord, FALSE );
		}

		// update request deatil
		UpdateRequestDetail();
	}

	// set status
	CString szText;
	szText.Format( _T("Ready  [ %d of %d Selected ]"), m_ctrlRequestList.GetSelectedCount(), m_nRecordCount );
	((CMainFrame*)GetParentFrame())->SetStatus( 0, szText );

	// start timer
	PauseTimer( FALSE );

	return TRUE;
}

BOOL CCelsusView::GetItemHighlight(LONGLONG nItemId, INT nColumn, LPCOLORREF pclrText, LPCOLORREF pclrTextBk, PINT pnWeight, PBOOL pbItalic, PBOOL pbUnderline)
{
	// get request
	REQUEST_DISPLAY_SET currentRequest;
	if( !m_mRequestSet.Lookup( nItemId, currentRequest ))
	{
		ASSERT( FALSE );
		return FALSE;
	}

	// set defaults
	*pclrText = appConfig.GetColorRef( m_aPriority.GetAt( currentRequest.m_priority_id ).szTextColor );
	*pclrTextBk = appConfig.GetColorRef( m_aPriority.GetAt( currentRequest.m_priority_id ).szBackGroundColor );

	// set read
	if( !currentRequest.m_touched )
		*pnWeight = FW_SEMIBOLD;

	// no highlights
	if( !m_bShowHighlights )
		return TRUE;

	// complete no date highlights
	if( m_nViewMode == TAB_COMPLETE )
		return TRUE;

	//TRACE( _T("Getting Highlight %d\n"), nItemId );

	// check date
	if( nColumn == COL_DATE )
	{
		COleDateTimeSpan t_index;		
		t_index = COleDateTime::GetCurrentTime() - currentRequest.m_date_in;
		// check time
		if( currentRequest.m_status_id >= STATUS_OFFSET_NA || currentRequest.m_touched || m_aPriority.GetAt( currentRequest.m_priority_id ).nInHours <= 0 )
		{
		}
		else if( t_index.GetTotalHours() > m_aPriority.GetAt( currentRequest.m_priority_id ).nInHours )
		{
			*pclrText = appConfig.GetColorRef( m_aPriority.GetAt( currentRequest.m_priority_id ).szTextColorOld );
			*pclrTextBk = appConfig.GetColorRef( m_aPriority.GetAt( currentRequest.m_priority_id ).szBackGroundColorOld );
		}
	}

	// check triage
	if( m_nCurrentLibrary != ID_TRG && nColumn == COL_ITEM )
	{
		if( currentRequest.m_library_id == ID_TRG )
			*pclrTextBk = appConfig.m_Colors.dwTriageHighlight;
	}

	// check online
	if( nColumn == COL_DETAIL )
	{
		if( currentRequest.m_webcheck < 1 && !appConfig.GetIDFromRequest( currentRequest.m_request ).IsEmpty() )
			*pbUnderline = TRUE;
	}

	// check source
	if( nColumn == COL_UID )
	{
		if( currentRequest.m_status_id < STATUS_OFFSET_NA && currentRequest.m_webcheck & ID_CHECKED_ONLINE_LINK )
			*pbUnderline = TRUE;
	}

	// check source
	if( nColumn == COL_SOURCE )
	{
		// check for link
		if( currentRequest.m_status_id < STATUS_OFFSET_NA && !currentRequest.m_source_link.IsEmpty() )
		{
			*pbUnderline = TRUE;
			// check source material
			if( currentRequest.m_source_material == MATERIAL_ELECTRONIC_LICENSED )
				*pclrTextBk = appConfig.m_Colors.dwMaterialLicensed;
			else if( currentRequest.m_source_material == MATERIAL_ELECTRONIC_FREE )
				*pclrTextBk = appConfig.m_Colors.dwMaterialFree;
			else if( currentRequest.m_source_material == MATERIAL_ELECTRONIC_NOTFREE )
				*pclrTextBk = appConfig.m_Colors.dwMaterialNotFree;
		}
	}

	// not highlighting
	if( !m_bHighlightDuplicate )
		return TRUE;

	// return if touched
	if( currentRequest.m_touched )
		return TRUE;
	// return if only one
	if( m_nRecordCount <= 2 )
		return TRUE;

	// check duplicate
	if( nColumn == COL_EMAIL )
	{
		BOOL bDuplicate = FALSE;

		// get request
		m_mRequestSet.Lookup( nItemId, currentRequest );

		// get current information
		LONG nCurrentID = currentRequest.m_user_id;

		// get previous
		if( nItemId > 0 && m_nRecordCount > 1 )
		{
			// get request
			if( m_mRequestSet.Lookup( nItemId - 1, currentRequest ))
			{
				// check for duplicate
				if( nCurrentID == currentRequest.m_user_id )
				{
					bDuplicate = TRUE;
				}
			}
		}
		// get next
		if( nItemId + 1 < m_nRecordCount )
		{
			// get request
			if( m_mRequestSet.Lookup( nItemId + 1, currentRequest ))
			{
				// check for duplicate
				if( nCurrentID == currentRequest.m_user_id )
				{
					bDuplicate = TRUE;
				}
			}
		}
		// duplicate?
		if( bDuplicate )
		{	
			*pclrTextBk = appConfig.m_Colors.dwDuplicateHighlight;
		}
	}
	// return
	return TRUE;
}

INT CCelsusView::GetItemImage(LONGLONG nItemId, INT nColumn)
{
	INT nImage = ICON_NONE;

	REQUEST_DISPLAY_SET currentRequest;
	if( !m_mRequestSet.Lookup( nItemId, currentRequest ))
	{
		ASSERT( FALSE );
		return ICON_NONE;
	}

	// check column
	switch( nColumn )
	{
		// set delivery schedule
		case COL_SCHEDULE:
			// set icon
			if( m_aPriority.GetAt( currentRequest.m_priority_id ).nIcon >= 0 )
				nImage = m_aPriority.GetAt( currentRequest.m_priority_id ).nIcon;
			else
				nImage = ICON_NONE;

			// hold takes precedence
			if( m_aStatus.GetAt( currentRequest.m_status_id ).nIcon >= 0 )
				nImage = m_aStatus.GetAt( currentRequest.m_status_id ).nIcon;
			// problem take repcedence
			if( m_aLibrary.GetAt( currentRequest.m_library_id ).nType & ID_PROBLEM_LIBRARY )
				nImage = ICON_PROBLEM;
			break;
		// set delivery method
		case COL_DELIVERY:
			if( m_aLibrary.GetAt( currentRequest.m_library_id ).nType & ID_INTERNAL_ILL_LIBRARY )
				nImage = ICON_LENDING_ILL;
			else if( m_aLibrary.GetAt( currentRequest.m_library_id ).nType & ID_EXTERNAL_ILL_LIBRARY )
				nImage = ICON_BORROWING_ILL;
			else
			{
				// set icon
				if( currentRequest.m_status_id >= STATUS_OFFSET_ILL && currentRequest.m_status_id <= STATUS_OFFSET_ILL + 99 )
					nImage = ICON_LENDING_ILL;
				else if( m_aMethod.GetAt( currentRequest.m_method_id ).nIcon >= 0 )
					nImage = m_aMethod.GetAt( currentRequest.m_method_id ).nIcon;
				else
					nImage = ICON_NONE;
			}
			break;
		// set collection icon
		case COL_COLLECTION:
			if( m_aCollection.GetAt( currentRequest.m_collection_id ).nIcon >= 0 )
				nImage = m_aCollection.GetAt( currentRequest.m_collection_id ).nIcon;
			else
				nImage = ICON_NONE;
			break;
		// set date icon
		case COL_ITEM:
			{
				if( currentRequest.m_status_id < STATUS_OFFSET_NA )
				{
					// check for triage
					if( nImage == ICON_TIME && currentRequest.m_library_id == ID_TRG )
						nImage = ICON_TIME_TRIAGE;
					else if( currentRequest.m_library_id == ID_TRG )
						nImage = ICON_TRIAGE;

					// at libray
					if( currentRequest.m_atlibrary > 0 )
						nImage = ICON_AT_LIBRARY;

					// resubmitted
					if( currentRequest.m_step_id == STEP_ILL )
						nImage = ICON_NONE;

					// get date
					COleDateTimeSpan t_index;
					t_index = COleDateTime::GetCurrentTime() - currentRequest.m_date_in;
					// set old
					if( !currentRequest.m_touched && t_index.GetTotalHours() > m_aPriority.GetAt( currentRequest.m_priority_id ).nInHours )
						nImage = ICON_TIME;
				}
				else
				{
					// check tab
					if( currentRequest.m_status_id >= STATUS_OFFSET_NA && currentRequest.m_status_id < STATUS_ID_COMPLETE )
						nImage = ICON_NOT_AVAILABLE;
					if( currentRequest.m_invoiced > 0 )
						nImage = ICON_INVOICED;
				}
			}
			break;
		case COL_DATE:
			nImage = -1;
			break;
		case COL_DATE_HOLD:
			if( m_nViewMode == TAB_WORKER )
			{
				if( currentRequest.m_retain > 0 )
					nImage = ICON_TIME;
				else
					nImage = -1;
			}
			break;
		case COL_EMAIL:
			if( currentRequest.m_external_id > 0 )
				nImage = ICON_EXTERNAL;
			else
				nImage = ICON_NONE;
			break;
		case COL_LOCATION:
			nImage = ICON_NONE;
			break;
		case COL_DETAIL:
			if( currentRequest.m_status_id >= STATUS_OFFSET_NA )
				nImage = ICON_NONE;
			else if( currentRequest.m_webcheck < 1 && !appConfig.GetIDFromRequest( currentRequest.m_request ).IsEmpty() )
				nImage = ICON_WEB_CHECK;
			else
				nImage = ICON_NONE;
			break;
		case COL_UID:
			if( currentRequest.m_status_id >= STATUS_OFFSET_NA )
				nImage = ICON_NONE;
			else if( currentRequest.m_status_id < STATUS_OFFSET_NA && !currentRequest.m_request_link.IsEmpty() )
				nImage = ICON_WEB_LINK;
			else
				nImage = ICON_NONE;
			break;
		case COL_SOURCE:
			if( currentRequest.m_status_id >= STATUS_OFFSET_NA )
				nImage = ICON_NONE;
			else if( currentRequest.m_status_id < STATUS_OFFSET_NA && currentRequest.m_source_material == MATERIAL_ELECTRONIC_FREE && !currentRequest.m_source_link.IsEmpty() )
				nImage = ICON_WEB_FREE;
			else if( currentRequest.m_status_id < STATUS_OFFSET_NA && currentRequest.m_source_material == MATERIAL_ELECTRONIC_NOTFREE && !currentRequest.m_source_link.IsEmpty() )
				nImage = ICON_WEB_NOT_FREE;
			else if( currentRequest.m_status_id < STATUS_OFFSET_NA && !currentRequest.m_source_link.IsEmpty() )
				nImage = ICON_WEB_MAYBE;
			else
				nImage = ICON_NONE;
			break;
		case COL_WORKER:
			if( currentRequest.m_retain > 0 )
				nImage = ICON_TIME;
			else
				nImage = -1;
			break;
		// do default
		default:
			nImage = ICON_NONE;
			break;
	}
	// return image
	return nImage;
}

HCURSOR CCelsusView::GetItemCursor(LONGLONG nItemId, INT nColumn)
{
	HCURSOR hCursor = NULL;
	REQUEST_DISPLAY_SET currentRequest;
	if( !m_mRequestSet.Lookup( nItemId, currentRequest ))
	{
		ASSERT( FALSE );
		return NULL;
	}
	// check column
	if( nColumn == COL_SOURCE )
	{
		if( !currentRequest.m_source_link.IsEmpty() )
			hCursor = AfxGetApp()->LoadStandardCursor( IDC_HAND );
	}
	// return cursor
	return hCursor;
}

INT CCelsusView::ShowTabView(INT nTab, BOOL bShow)
{
	INT nCurrentTab = -1;

	// delete all
	m_ctrlTabSelection.DeleteAllItems();
	// set tab info
	if( m_bShowLibraryView )
	{
		// get library
		CString szLibrary = m_szaLibrary[m_nCurrentLibrary];
		if( m_aLibrary.GetAt(m_nCurrentLibrary).bDiverted )
			nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM | TCIF_IMAGE, TAB_LIBRARY, szLibrary, ICON_DIVERT, TAB_LIBRARY );
		else
			nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_LIBRARY, szLibrary, NULL, TAB_LIBRARY );
		if( nTab == TAB_LIBRARY )
			m_ctrlTabSelection.SetCurSel( nCurrentTab );
	}
	if( m_bShowMyView )
	{
		nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_WORKER, _T("My View"), NULL, TAB_WORKER );
		if( nTab == TAB_WORKER )
			m_ctrlTabSelection.SetCurSel( nCurrentTab );
	}
	if( m_bShowInProcessView )
	{
		// get library type
		INT nType = m_aLibrary.GetAt( m_nCurrentLibrary ).nType;
		BOOL bInternalILLLibrary = nType & ID_INTERNAL_ILL_LIBRARY ? TRUE : FALSE;
		BOOL bExternalILLLibrary = nType & ID_EXTERNAL_ILL_LIBRARY ? TRUE : FALSE;
		if( bInternalILLLibrary || bExternalILLLibrary )
			nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_PROCESS, _T("Processing"), NULL, TAB_PROCESS );
		else
			nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_PROCESS, _T("Scan Process"), NULL, TAB_PROCESS );
		if( nTab == TAB_PROCESS )
			m_ctrlTabSelection.SetCurSel( nCurrentTab );
	}
	if( m_bShowHoldView )
	{
		nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_HOLD, _T("Held Requests"), NULL, TAB_HOLD );
		if( nTab == TAB_PROCESS )
			m_ctrlTabSelection.SetCurSel( nCurrentTab );
	}
	if( m_bShowCurrentView )
	{
		nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_ARTICLES, _T("Current Requests"), NULL, TAB_ARTICLES );
		if( nTab == TAB_ARTICLES )
			m_ctrlTabSelection.SetCurSel( nCurrentTab );
	}
	if( m_bShowCompletedView )
	{
		nCurrentTab = m_ctrlTabSelection.InsertItem( TCIF_TEXT | TCIF_PARAM, TAB_COMPLETE, _T("Complete"), NULL, TAB_COMPLETE );
		if( nTab == TAB_COMPLETE )
			m_ctrlTabSelection.SetCurSel( nCurrentTab );
	}

	// set tab
	if( !bShow )
		m_ctrlTabSelection.SetCurSel( 0 );
	// set tab view
	SetTabView( GetTabView() );
	// return
	return nCurrentTab;
}

void CCelsusView::SetTabView(INT nTab)
{
	// change tab view
	switch( nTab )
	{
	// check library view
	case TAB_LIBRARY:
		// modfiy query time
		m_nTickerMultiplier = 1;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

		// set filter
		if( m_bShowTriage )
			m_szFilter.Format( _T("(requests.library_id = %ld OR requests.library_id = %ld) AND requests.status_id = %d"), m_nCurrentLibrary, ID_TRG, STATUS_ID_NEW );
		else
			m_szFilter.Format( _T("requests.library_id = %ld  AND requests.status_id = %d"), m_nCurrentLibrary, STATUS_ID_NEW );

		// hide columns
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, 0 );
		// set column text
        SetColumTitle( COL_DATE, _T("Date Requested"));
		break;
	// check hold view
	case TAB_HOLD:
		// modfiy query time
		m_nTickerMultiplier = 1;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

		// set filter
		m_szFilter.Format( _T("requests.library_id = %ld AND (requests.status_id >= %ld AND requests.status_id <= %ld)"), m_nCurrentLibrary, STATUS_OFFSET_HOLD, STATUS_OFFSET_HOLD + 99 );

		// hide columns		
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 0 );
		// show columns
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 180 );
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 90 );
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, 90 );
		// set column text
        SetColumTitle( COL_DATE, _T("Date Requested"));
        SetColumTitle( COL_DATE_HOLD, _T("Date Expected"));
		break;
	// check worker view
	case TAB_WORKER:
		// modfiy query time
		m_nTickerMultiplier = TICKER_MULTIPLIER;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

		// set filter
		m_szFilter.Format( _T("requests.staff_id = %ld  AND requests.status_id = %d"), m_nStaffID, STATUS_ID_PENDING );

		// hide columns
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 0 );
		// show columns
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, 90 );
		// set column text
        SetColumTitle( COL_DATE, _T("Date Requested"));
        SetColumTitle( COL_DATE_HOLD, _T("Date Claimed"));
		break;
	// check in process view
	case TAB_PROCESS:
		// modfiy query time
		m_nTickerMultiplier = 1;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

		// set filter
		m_szFilter.Format( _T("requests.library_id = %ld AND requests.status_id = %ld"), m_nCurrentLibrary, STATUS_ID_IN_PROCESS );

		// hide columns
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, 0 );
		// show column
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 90 );
		// set column text
        SetColumTitle( COL_DATE, _T("Date Requested"));
		break;
	// check normal view
	case TAB_ARTICLES:
		// modfiy query time
		m_nTickerMultiplier = TICKER_MULTIPLIER;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

		// set filter
		m_szFilter.Format( _T("requests.status_id < %ld"), STATUS_OFFSET_NA );

		// show columns
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 90 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 180 );
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 90 );
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, 0 );
		break;
		// set column text
        SetColumTitle( COL_DATE, _T("Date Requested"));
	// check complete
	case TAB_COMPLETE:
		// modfiy query time
		m_nTickerMultiplier = TICKER_MULTIPLIER_LONG;
		m_nTicker = appConfig.m_Database.nRefreshTime * m_nTickerMultiplier;

		// set filter
		if( appConfig.m_General.nDaysShownComplete > 0 )
			m_szFilter.Format( _T("requests.library_id = %ld AND requests.status_id >= %ld AND requests.date_out >= DATE_SUB(NOW(), INTERVAL %d DAY)"), m_nCurrentLibrary, STATUS_OFFSET_NA, appConfig.m_General.nDaysShownComplete );
		else
			m_szFilter.Format( _T("requests.library_id = %ld AND requests.status_id >= %ld"), m_nCurrentLibrary, STATUS_OFFSET_NA );

		// show columns
		m_ctrlRequestList.SetColumnWidth( COL_WORKER, 90 );
		m_ctrlRequestList.SetColumnWidth( COL_LIBRARY, 0 );
		m_ctrlRequestList.SetColumnWidth( COL_STATUS, 180 );
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, 0 );
		// set column text
        SetColumTitle( COL_DATE, _T("Date Complete"));
		break;
	default:
		m_szFilter.Empty();
	}
	// refresh
	RefreshList( TRUE );
}

INT CCelsusView::GetTabView(void)
{
	// get tab view from extra info
	TCITEM tcItem;
	tcItem.mask = TCIF_PARAM;
	tcItem.lParam = -1;
	if( !m_ctrlTabSelection.GetItem( m_ctrlTabSelection.GetCurSel(), &tcItem ) )
	{
		m_ctrlTabSelection.SetCurSel( TAB_LIBRARY );
		m_nViewMode = TAB_LIBRARY;
	}
	else
		m_nViewMode = (INT)tcItem.lParam;

	return m_nViewMode;
}

void CCelsusView::SetColumTitle(INT nColumn, CString szText)
{
	LVCOLUMN lvColumn;

	// set column text
	ZeroMemory(&lvColumn, sizeof(lvColumn));
	lvColumn.mask = LVCF_TEXT; 
    lvColumn.pszText = szText.GetBuffer(); 
	m_ctrlRequestList.SetColumn( nColumn, &lvColumn );
	szText.ReleaseBuffer();
}

void CCelsusView::SetTabTitle(INT nTab, CString szAdd, BOOL bRestore)
{
	TCITEM tcItem;
	CString szString;

	//  Get the current tab item text.
	TCHAR buffer[256] = {0};
	tcItem.pszText = buffer;
	tcItem.cchTextMax = 256;
	tcItem.mask = TCIF_TEXT;

	m_ctrlTabSelection.GetItem( nTab, &tcItem );

	// restrore tab
	if( bRestore )
	{
		// reset sort
		m_nSortBy = SORT_NORMAL;

		//  Set the new text for the item.
		INT nIndex = 0;
		szString = tcItem.pszText;
		nIndex = szString.Find( _T("[") ) - 1;
		szString = szString.Left( nIndex );
		if( nIndex > 0 )
		{
			tcItem.pszText = szString.LockBuffer();
			//  Set the item in the tab control.
			m_ctrlTabSelection.SetItem( nTab, &tcItem );
			szString.UnlockBuffer();
		}
	}
	else
	{
		CString szCurrent;
		// already there
		if( szCurrent.Find( szAdd ) == -1 )
		{
			//  Set the new text for the item.
			szString.Format( _T("%s %s"), tcItem.pszText, szAdd ); 
			tcItem.pszText = szString.LockBuffer();
			//  Set the item in the tab control.
			m_ctrlTabSelection.SetItem( nTab, &tcItem );
			szString.UnlockBuffer();
		}
	}
}

BOOL CCelsusView::GetColumnOrder(void)
{
	// get header
	CHeaderCtrl* pHeaderCtrl = m_ctrlRequestList.GetHeaderCtrl();
	if( pHeaderCtrl != NULL )
	{
		INT nCount = AfxGetApp()->GetProfileInt( _T("Settings"), _T("Column_Count"), 0);
		if( nCount != pHeaderCtrl->GetItemCount() )
			return FALSE;

		BOOL bRetVal = FALSE;
		UINT bytes;
		INT *pnColOrder = NULL;
		if(( AfxGetApp()->GetProfileBinary( _T("Settings"), _T("Column_Order"), (BYTE **)&pnColOrder, &bytes ) && bytes == sizeof(INT) * nCount ))
		{
			bRetVal = m_ctrlRequestList.SetColumnOrderArray( nCount, pnColOrder );
		}
		delete[] pnColOrder;

		return bRetVal;
	}
	return FALSE;
}

BOOL CCelsusView::SetColumnOrder(void)
{
	// get header
	CHeaderCtrl* pHeaderCtrl = m_ctrlRequestList.GetHeaderCtrl();
	if( pHeaderCtrl != NULL )
	{
		BOOL bGood = TRUE;

		INT nCount = pHeaderCtrl->GetItemCount();
		if( !AfxGetApp()->WriteProfileInt( _T("Settings"), _T("Column_Count"), nCount) )
			bGood = FALSE;

		INT *pnColOrder = new INT[nCount];
		m_ctrlRequestList.GetColumnOrderArray( pnColOrder, nCount );

		if( !AfxGetApp()->WriteProfileBinary( _T("Settings"), _T("Column_Order"), (BYTE*)pnColOrder, sizeof(INT) * nCount) )
			bGood = FALSE;

		delete[] pnColOrder;
		return bGood;
	}
	return FALSE;
}

INT CCelsusView::GetColumnID(void)
{
	// get subitem
	INT nSubItemId = -1;
	LVHITTESTINFO hti;

	CPoint point;
	GetCursorPos( &point );
	ScreenToClient( &point );
	
	hti.pt = point;
	hti.flags = LVM_SUBITEMHITTEST;
	m_ctrlRequestList.SubItemHitTest( &hti );
	nSubItemId = hti.iSubItem;

	return nSubItemId;
}

INT CCelsusView::GetColumnID(CPoint point)
{
	// get subitem
	INT nSubItemId = -1;
	LVHITTESTINFO hti;

	hti.pt = point;
	hti.flags = LVM_SUBITEMHITTEST;
	m_ctrlRequestList.SubItemHitTest( &hti );
	nSubItemId = hti.iSubItem;

	return nSubItemId;
}

LONGLONG CCelsusView::UpdateRequestArray(BOOL bUseHints)
{
	CWaitCursor Wait;

	// kill the timer
	PauseTimer();

	// request full array
	if( !bUseHints )
	{
		TRACE( _T("Updating Array: No Hints\n") );
		// update array and save count
		ULONG nCount = appConfig.m_SQL.GetFullRequestMap( &m_mRequestSet, m_szSort, m_szFilter );
		// return count
		return nCount;
	}

	// init/update cache
	if( m_bResetCache || ( m_nCacheFrom == -1 && m_nCacheTo == -1 ))
	{
		TRACE( _T("Updating Array: Full (-1)\n") );
		appConfig.m_SQL.GetFullRequestMap( &m_mRequestSet, m_szSort, m_szFilter, 0, appConfig.m_Database.nLimit );		
		// reset
		m_bResetCache = FALSE;
	}
	else
	{
		//m_nRecordCount
		REQUEST_DISPLAY_SET currentRequest;
		// check from
		if( !m_mRequestSet.Lookup( m_nCacheFrom, currentRequest ))
		{
			TRACE( _T("Updating Array: Full\n") );

			INT nFrom = m_nCacheFrom - appConfig.m_Database.nRange;
			if( nFrom < 0 ) nFrom = 0;
			appConfig.m_SQL.GetFullRequestMap( &m_mRequestSet, m_szSort, m_szFilter, nFrom, appConfig.m_Database.nLimit );
		}
		// check to
		else if( !m_mRequestSet.Lookup( m_nCacheTo, currentRequest ))
		{
			INT nRange = m_nCacheTo - m_nCacheFrom;
			// check range and add
			if( nRange < 5 )
			{
				TRACE( _T("Updating Array: Add\n") );
				// add to range
				appConfig.m_SQL.AddFullRequestMap( &m_mRequestSet, m_szSort, m_szFilter, m_nCacheFrom, nRange + appConfig.m_Database.nRange );				
			}
			else
			{
				TRACE( _T("Updating Array: New\n") );
				// get new range
				appConfig.m_SQL.GetFullRequestMap( &m_mRequestSet, m_szSort, m_szFilter, m_nCacheFrom, appConfig.m_Database.nLimit );				
			}
		}
		else
		{
			TRACE( _T("Array Cached\n") );
		}
	}

	// start the timer
	PauseTimer( FALSE );

	// update request deatil
	UpdateRequestDetail();

	// return count
	return m_nRecordCount;
}

BOOL CCelsusView::UpdateRequestDetail(void)
{
	CString szHTMLFile;
	REQUEST_DISPLAY_SET Request;
	BOOL bGetRequest = FALSE;

	if( m_nRecordCount > 0 )
		bGetRequest = m_mRequestSet.Lookup( m_nCurrentRecord, Request );

	// clear data
	if( m_bInitialized && ( !bGetRequest || m_nRecordCount == 0 ))
	{
		// navigate to show browser window
		m_wbRequest.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
		m_wbInformation.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
		m_wbRequester.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );

		UpdateData( FALSE );
		return FALSE;
	}

	TRACE( _T("Updating Request\n") );

	// get request
	appConfig.m_SQL.GetFullRequest( &m_CurrentRequest, Request.m_id );

	// check user
	if( m_CurrentRequest.m_user_id >= m_aUserInfo.GetCount() )
		GetUsers();

	// adjust widths in list
	if( !m_bInitialized )
	{
		m_bInitialized = TRUE;
		// set column width
		m_ctrlRequestList.SetColumnWidth( COL_DATE, LVSCW_AUTOSIZE );
	}
	// set column width	for hold date
	if( m_nViewMode == TAB_HOLD || m_nViewMode == TAB_WORKER )
		m_ctrlRequestList.SetColumnWidth( COL_DATE_HOLD, LVSCW_AUTOSIZE );

	// clear information
	appConfig.ClearHTML( &m_wbRequest );
	// read requester info file
	szHTMLFile = m_szRequestFile;
	// format macros
	FormatCurrentMacros( &szHTMLFile );
	// set HTML
	appConfig.SetHTML( &m_wbRequest, szHTMLFile );

	// set request window
	if( m_bShowRequestWindow && m_pRequestViewDlg )
	{
		// set view
		m_pRequestViewDlg->SetView( m_CurrentRequest.m_id, szHTMLFile );
	}

	// clear information
	appConfig.ClearHTML( &m_wbInformation );
	// read requester info file
	szHTMLFile = m_szInformationFile;
	// format macros
	FormatCurrentMacros( &szHTMLFile );
	// set HTML
	appConfig.SetHTML( &m_wbInformation, szHTMLFile );

	// clear requester
	appConfig.ClearHTML( &m_wbRequester );
	// read requester info file
	szHTMLFile = m_szRequesterFile;
	// format macros
	FormatCurrentMacros( &szHTMLFile );
	// set HTML
	appConfig.SetHTML( &m_wbRequester, szHTMLFile );

	return UpdateData( FALSE );
}

BOOL CCelsusView::FormatCurrentMacros(CString* pszString)
{
	// check for valid
	if( m_CurrentRequest.m_id < 0 )
	{
		// navigate to show browser window
		m_wbRequest.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
		m_wbInformation.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );
		m_wbRequester.Navigate( _T("About:Blank"), NULL, NULL, NULL, NULL );

		UpdateData( FALSE );
		return FALSE;
	}

	CString szTemp;
	// replace macros
	szTemp.Format( _T("%ld"), m_CurrentRequest.m_id );
	pszString->Replace( _T("(REQUESTID)"), szTemp );

	// treat new lines as breaks in request
	szTemp = m_CurrentRequest.m_request;
	szTemp.Replace( _T("\n"), _T("<br/>") );
	pszString->Replace( _T("(REQUEST)"), szTemp );

	pszString->Replace( _T("(REQUESTSOURCE)"), m_CurrentRequest.m_source );
	pszString->Replace( _T("(REQUESTINSTRUCTIONS)"), m_CurrentRequest.m_instructions );
	pszString->Replace( _T("(REQUESTINFORMATION)"), m_CurrentRequest.m_information );
	pszString->Replace( _T("(REQUESTNOTES)"), m_CurrentRequest.m_notes );
	pszString->Replace( _T("(REQUESTUID)"), m_CurrentRequest.m_uid );
	pszString->Replace( _T("(SOURCENOTES)"), m_CurrentRequest.m_source_notes );
	pszString->Replace( _T("(REQUEST_LINK)"), m_CurrentRequest.m_link );

	// alternate location
	if( !m_CurrentRequest.m_location.IsEmpty() )
	{
		pszString->Replace( _T("(DELIVERY_LOCATION)"), m_CurrentRequest.m_location );
	}
	else
	{
		if( appConfig.m_Options.bUseComapnyForLocation )
			pszString->Replace( _T("(DELIVERY_LOCATION)"), m_CurrentRequest.m_users_company );
		else
			pszString->Replace( _T("(DELIVERY_LOCATION)"), m_CurrentRequest.m_users_address1 );
	}

	// check for user deleted
	if( m_CurrentRequest.m_id == -1 )
	{
		// replace strings
		pszString->Replace( _T("(USERNAME)"), _T("[User Deleted]") );
		pszString->Replace( _T("(USEREMAIL)"), _T("[User Deleted]") );
		pszString->Replace( _T("(USERPHONE)"), _T("[User Deleted]") );
		pszString->Replace( _T("(USERFAX)"), _T("[User Deleted]") );
		pszString->Replace( _T("(USERCOMPANY)"), _T("[User Deleted]") );
	}
	else
	{
		// replace strings
		pszString->Replace( _T("(USERNAME)"), m_CurrentRequest.m_users_name );
		pszString->Replace( _T("(USEREMAIL)"), m_CurrentRequest.m_users_email );
		pszString->Replace( _T("(USERPHONE)"), m_CurrentRequest.m_users_phone );
		pszString->Replace( _T("(USERFAX)"), m_CurrentRequest.m_users_fax );
		pszString->Replace( _T("(USERCOMPANY)"), m_CurrentRequest.m_users_company );
	}

	pszString->Replace( _T("(PRIORITY)"), m_szaPriority.GetAt( m_CurrentRequest.m_priority_id ));
	pszString->Replace( _T("(METHOD)"), m_szaMethod.GetAt( m_CurrentRequest.m_method_id ));
	pszString->Replace( _T("(LIBRARY)"), m_szaLibrary.GetAt( m_CurrentRequest.m_library_id ));
	szTemp.Format( _T("%d"), m_CurrentRequest.m_redirected );
	pszString->Replace( _T("(REDIRECTED)"), szTemp );
	pszString->Replace( _T("(ILLYESNO)"), m_szaILL.GetAt( m_CurrentRequest.m_ill_id ));
	pszString->Replace( _T("(PROJECT)"), m_CurrentRequest.m_project );

	// status
	pszString->Replace( _T("(STATUS)"), m_aStatus.GetAt( m_CurrentRequest.m_status_id ).szExplanation );
	pszString->Replace( _T("(STATUS_EXPLANATION)"), m_aStatus.GetAt( m_CurrentRequest.m_status_id ).szExplanation );
	pszString->Replace( _T("(STATUS_SUBJECT)"), m_aStatus.GetAt( m_CurrentRequest.m_status_id ).szSubject );
	pszString->Replace( _T("(STATUS_MESSAGE)"), m_aStatus.GetAt( m_CurrentRequest.m_status_id ).szMessage );
	pszString->Replace( _T("(STATUS_CODE)"), m_aStatus.GetAt( m_CurrentRequest.m_status_id ).szCode );

	// status filled not filled
	if( m_CurrentRequest.m_status_id == STATUS_ID_NEW )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );
	else if( m_CurrentRequest.m_status_id == STATUS_ID_PENDING )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );
	else if( m_CurrentRequest.m_status_id == STATUS_ID_IN_PROCESS )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );
	else if( m_CurrentRequest.m_status_id >= STATUS_OFFSET_HOLD && m_CurrentRequest.m_status_id < STATUS_OFFSET_HOLD + 100 )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );
	else if( m_CurrentRequest.m_status_id >= STATUS_OFFSET_ILL && m_CurrentRequest.m_status_id < STATUS_OFFSET_ILL + 100 )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );
	else if( m_CurrentRequest.m_status_id >= STATUS_OFFSET_PROBLEM && m_CurrentRequest.m_status_id < STATUS_OFFSET_PROBLEM + 100 )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );
	else if( m_CurrentRequest.m_status_id >= STATUS_OFFSET_NA && m_CurrentRequest.m_status_id < STATUS_OFFSET_NA + 100 )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Not Filled") );
	else if( m_CurrentRequest.m_status_id == STATUS_ID_COMPLETE )
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Filled") );
	else
		pszString->Replace( _T("(STATUS_FILLED)"), _T("Status") );

	// get staff info
	if( m_aStaffInfo.GetCount() >= m_CurrentRequest.m_staff_id )
	{
		if( m_aStaffInfo.GetAt( m_CurrentRequest.m_staff_id ).nStaffID > 0 )
		{
			pszString->Replace( _T("(WORKERLINK)"), appConfig.m_General.szWorkerLink );
			pszString->Replace( _T("(STAFFEMAIL)"), m_aStaffInfo.GetAt( m_CurrentRequest.m_staff_id ).szStaffEmail );
			pszString->Replace( _T("(STAFFNAME)"), m_aStaffInfo.GetAt( m_CurrentRequest.m_staff_id ).szStaffName );
		}
		else
		{
			pszString->Replace( _T("(WORKERLINK)"), appConfig.m_General.szWorkerLink );
			pszString->Replace( _T("(STAFFEMAIL)"), _T("") );
			pszString->Replace( _T("(STAFFNAME)"), _T("") );
		}
	}
	else
	{
		pszString->Replace( _T("(WORKERLINK)"), appConfig.m_General.szWorkerLink );
		pszString->Replace( _T("(STAFFEMAIL)"), _T("") );
		pszString->Replace( _T("(STAFFNAME)"), _T("") );
	}

	return TRUE;
}

BOOL CCelsusView::ShowRequestDlg(BOOL bShow)
{
	// show request dialog modeless
	if( !m_pRequestViewDlg )
	{
		m_pRequestViewDlg = new CDlgRequestView(this);
		m_pRequestViewDlg->Create( IDD_DIALOG_REQUEST_VIEW );
	}

	// hide window
	if( !bShow )
		return m_pRequestViewDlg->ShowWindow( SW_HIDE );

	// check for request
	if( m_CurrentRequest.m_id < 0 )
	{
		// no request init
		m_pRequestViewDlg->InitView();
	}
	else
	{
		if( ::IsWindow( m_pRequestViewDlg->GetSafeHwnd() ))
		{
			CString szHTMLFile;
			// read requester info file
			szHTMLFile = m_szRequestFile;
			// format macros
			FormatCurrentMacros( &szHTMLFile );
			// set view
			m_pRequestViewDlg->SetView( m_CurrentRequest.m_id, szHTMLFile );
		}
	}

	// show window
	return m_pRequestViewDlg->ShowWindow( SW_SHOW );
}

BOOL CCelsusView::LoadItemIcons(void)
{
	HICON hIcon = NULL;
	HBITMAP hBitmap = NULL;
	CString szPath;
	BOOL bIconsLoaded = TRUE;

	// create image list
	m_ilImages.DeleteImageList();
	m_ilImages.Create( ICON_LIST_SIZE, ICON_LIST_SIZE, ILC_COLOR32 | ILC_MASK, 0, 1 );

	// specify path
	szPath = appConfig.m_General.szStatusIconPath;
	// get exe path
	if( szPath.Find( '\\' ) == -1 )
	{
		INT nIndex = 0;
		CString szAppPath;
		TCHAR cBuffer[MAX_PATH];

		memset( cBuffer, NULL, MAX_PATH );
		GetModuleFileName( NULL, cBuffer, MAX_PATH );
		szAppPath = cBuffer;
		nIndex = szAppPath.ReverseFind('\\');
		szAppPath = szAppPath.Left( nIndex );
		szPath.Format( _T("%s\\%s"), szAppPath, szPath );
	}
	// check for trainling backslash
	if( szPath.Right( 1 ) != _T("\\") )
		szPath += _T("\\");

	// load status icons
	hIcon = (HICON)LoadImage( NULL, szPath + _T("blank.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_BLANK ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("problem.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_PROBLEM ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("triage.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_TRIAGE ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;
	
	hIcon = (HICON)LoadImage( NULL, szPath + _T("atlibrary.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_AT_LIBRARY ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("invoiced.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_INVOICED ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;
	
	hIcon = (HICON)LoadImage( NULL, szPath + _T("i_ill.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_I_ILL ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;
	
	hIcon = (HICON)LoadImage( NULL, szPath + _T("e_ill.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_E_ILL ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;
	
	hIcon = (HICON)LoadImage( NULL, szPath + _T("past_due.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_PAST_DUE ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;
	
	hIcon = (HICON)LoadImage( NULL, szPath + _T("past_due_triage.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_PAST_DUE_TRIAGE ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;
	
	hIcon = (HICON)LoadImage( NULL, szPath + _T("web_check.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_WEB_CHECK ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("web_link.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_WEB_LINK ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("web_maybe.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_WEB_MAYBE ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("web_free.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_WEB_FREE ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("web_not_free.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_WEB_NOT_FREE ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("resubmitted.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_RESUBMITTED ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("not_availble.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_NOT_AVAILABLE_SMALL ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("external.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_EXTERNAL ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	hIcon = (HICON)LoadImage( NULL, szPath + _T("diverted.ico"), IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
	if( !hIcon )
		hIcon = (HICON)LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_ICON_DIVERTED ));
	if( hIcon )
		m_ilImages.Add( hIcon );
	else
		bIconsLoaded = FALSE;

	// inform user
	if( !bIconsLoaded )
		AfxMessageBox( _T("ERROR:\n\nError loading information icons."), MB_ICONSTOP );

	// add priorities
	for( INT_PTR nCount = 0; nCount < m_aPriority.GetCount(); nCount++ )
	{
		// get icon path
		szPath = m_aPriority.GetAt( nCount ).szIconFile;
		if( !szPath.IsEmpty() )
		{
			// get exe path
			if( szPath.Find( '\\' ) == -1 )
			{
				INT nIndex = 0;
				CString szAppPath;
				TCHAR cBuffer[MAX_PATH];

				memset( cBuffer, NULL, MAX_PATH );
				GetModuleFileName( NULL, cBuffer, MAX_PATH );
				szAppPath = cBuffer;
				nIndex = szAppPath.ReverseFind('\\');
				szAppPath = szAppPath.Left( nIndex );
		
				szPath.Format( _T("%s\\%s"), szAppPath, szPath );
			}

			// load icon
			hIcon = (HICON)LoadImage( NULL, szPath, IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check for bitmap
			if( !hIcon )
				hBitmap = (HBITMAP)LoadImage( NULL, szPath, IMAGE_BITMAP, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check icon and add to image list
			if( hIcon )
			{
				// add the enabled icon
				m_aPriority.GetAt( nCount ).nIcon = m_ilImages.Add( hIcon );
			}
			// check bitmap and add to image list
			else if( hBitmap )
			{
				CBitmap bitmap;
				// get bitmap
				bitmap.Attach( hBitmap );
				// add the enabled icon
				m_aPriority.GetAt( nCount ).nIcon = m_ilImages.Add( &bitmap, RGB( 255,0,255 ));
			}
			// no icon or bitmap set to -1
			else
			{
				CString szMessage;
				szMessage.Format( _T("No icon found for Priority (path=%s"), szPath );
				AfxMessageBox( szMessage );
				m_aPriority.GetAt( nCount ).nIcon = -1;
			}
		}
		else
		{
			// no path
			m_aPriority.GetAt( nCount ).nIcon = -1;
		}
	}

	// add methods
	for( INT_PTR nCount = 0; nCount < m_aMethod.GetCount(); nCount++ )
	{
		// get path
		szPath = m_aMethod.GetAt( nCount ).szIconFile;
		if( !szPath.IsEmpty() )
		{
			// get exe path
			if( szPath.Find( '\\' ) == -1 )
			{
				INT nIndex = 0;
				CString szAppPath;
				TCHAR cBuffer[MAX_PATH];

				memset( cBuffer, NULL, MAX_PATH );
				GetModuleFileName( NULL, cBuffer, MAX_PATH );
				szAppPath = cBuffer;
				nIndex = szAppPath.ReverseFind('\\');
				szAppPath = szAppPath.Left( nIndex );
		
				szPath.Format( _T("%s\\%s"), szAppPath, szPath );
			}

			// load icon
			hIcon = (HICON)LoadImage( NULL, szPath, IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check for bitmap
			if( !hIcon )
				hBitmap = (HBITMAP)LoadImage( NULL, szPath, IMAGE_BITMAP, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check icon and add to image list
			if( hIcon )
			{
				// add the enabled icon
				m_aMethod.GetAt( nCount ).nIcon = m_ilImages.Add( hIcon );
			}
			// check bitmap and add to image list
			else if( hBitmap )
			{
				CBitmap bitmap;
				// get bitmap
				bitmap.Attach( hBitmap );
				// add the enabled icon
				m_aMethod.GetAt( nCount ).nIcon = m_ilImages.Add( &bitmap, RGB( 255,0,255 ));
			}
			// no icon or bitmap set to -1
			else
				m_aMethod.GetAt( nCount ).nIcon = -1;
		}
		else
		{
			// no path
			m_aMethod.GetAt( nCount ).nIcon = -1;
		}
	}

	// add collections
	for( INT_PTR nCount = 0; nCount < m_aCollection.GetCount(); nCount++ )
	{
		// get path
		szPath = m_aCollection.GetAt( nCount ).szIconFile;
		if( !szPath.IsEmpty() )
		{
			// get exe path
			if( szPath.Find( '\\' ) == -1 )
			{
				INT nIndex = 0;
				CString szAppPath;
				TCHAR cBuffer[MAX_PATH];

				memset( cBuffer, NULL, MAX_PATH );
				GetModuleFileName( NULL, cBuffer, MAX_PATH );
				szAppPath = cBuffer;
				nIndex = szAppPath.ReverseFind('\\');
				szAppPath = szAppPath.Left( nIndex );
		
				szPath.Format( _T("%s\\%s"), szAppPath, szPath );
			}

			// load icon
			hIcon = (HICON)LoadImage( NULL, szPath, IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check for bitmap
			if( !hIcon )
				hBitmap = (HBITMAP)LoadImage( NULL, szPath, IMAGE_BITMAP, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check icon and add to image list
			if( hIcon )
			{
				// add the enabled icon
				m_aCollection.GetAt( nCount ).nIcon = m_ilImages.Add( hIcon );
			}
			// check bitmap and add to image list
			else if( hBitmap )
			{
				CBitmap bitmap;
				// get bitmap
				bitmap.Attach( hBitmap );
				// add the enabled icon
				m_aCollection.GetAt( nCount ).nIcon = m_ilImages.Add( &bitmap, RGB( 255,0,255 ));
			}
			// no icon or bitmap set to -1
			else
				m_aCollection.GetAt( nCount ).nIcon = -1;
		}
		else
		{
			// no path
			m_aCollection.GetAt( nCount ).nIcon = -1;
		}
	}

	// add status
	for( INT_PTR nCount = 0; nCount < m_aStatus.GetCount(); nCount++ )
	{
		// get path
		szPath = m_aStatus.GetAt( nCount ).szIconFile;
		if( !szPath.IsEmpty() )
		{
			// get exe path
			if( szPath.Find( '\\' ) == -1 )
			{
				INT nIndex = 0;
				CString szAppPath;
				TCHAR cBuffer[MAX_PATH];

				memset( cBuffer, NULL, MAX_PATH );
				GetModuleFileName( NULL, cBuffer, MAX_PATH );
				szAppPath = cBuffer;
				nIndex = szAppPath.ReverseFind('\\');
				szAppPath = szAppPath.Left( nIndex );
		
				szPath.Format( _T("%s\\%s"), szAppPath, szPath );
			}

			// load icon
			hIcon = (HICON)LoadImage( NULL, szPath, IMAGE_ICON, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check for bitmap
			if( !hIcon )
				hBitmap = (HBITMAP)LoadImage( NULL, szPath, IMAGE_BITMAP, ICON_LIST_SIZE, ICON_LIST_SIZE, LR_LOADFROMFILE );
			// check icon and add to image list
			if( hIcon )
			{
				// add the enabled icon
				m_aStatus.GetAt( nCount ).nIcon = m_ilImages.Add( hIcon );
			}
			// check bitmap and add to image list
			else if( hBitmap )
			{
				CBitmap bitmap;
				// get bitmap
				bitmap.Attach( hBitmap );
				// add the enabled icon
				m_aStatus.GetAt( nCount ).nIcon = m_ilImages.Add( &bitmap, RGB( 255,0,255 ));
			}
			// no icon or bitmap set to -1
			else
				m_aStatus.GetAt( nCount ).nIcon = -1;
		}
		else
		{
			// no path
			m_aStatus.GetAt( nCount ).nIcon = -1;
		}
	}

	// assign image list
	m_ctrlRequestList.SetImageList( &m_ilImages, LVSIL_SMALL );

	return TRUE;
}
